Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 27th, 2006, 05:13 PM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default C++ and main for a beginner

Do you have to end every C++ program with "void main()" or can you end it with anything as long as it calls the other functions in the code? Only reason I ask is I left it out and the compiler would not compile without it.
:(
Craig
Reply With Quote
  #2 (permalink)  
Old January 27th, 2006, 11:05 PM
Authorized User
 
Join Date: Mar 2005
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to Alan-LB Send a message via Yahoo to Alan-LB
Default

main() is the main function of all C and C++ programs so it must be in your program.

Any elementary textbook will explain this

Alan


Reply With Quote
  #3 (permalink)  
Old February 27th, 2006, 09:32 PM
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default


 Well, you could be tricky w/ the linker and name it something else if you were *really* determined too, but essentially, yes, every ANSI/ISO compliant program must contain a main() function ... not that sometime auto-generated code, for example Win32 project code created by the Visual C++ 5/6 IDE does *not*, however it has a main() funtion in the standard libraries it imports for you.

 HOWEVER you do NOT need to *end* your program in main(). your "void main()" can go anywhere in your program you like ... AFAIK the ending your program w/ main() was an old Pascal convention. I like to have my main() function at the beginning of the file it's in, but that's just personal preference.

Regards,
Meredith Shaebanyan

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Main Builder Delthor Java Basics 0 January 3rd, 2008 07:41 AM
sub main missing. arygullo VB.NET 1 June 19th, 2007 09:38 AM
Help with Main Menu GAF General .NET 0 March 18th, 2005 08:10 PM
Main Method CodeMonkeys C# 1 August 11th, 2004 06:51 AM
To Imar: Re: Sub Main shadowpug VB.NET 2002/2003 Basics 1 July 26th, 2003 02:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.