-
July 9th, 2012, 02:49 PM
#1
A beginner's question on how main "should be" structured.
After learning C++ on my own from books, I'm about to start writing code for my first project, a craps game. I've seen code where main just calls a class function and all of the code starts with that function. Like:
Code:
int main()
{
Game::Start();
Return 0;
}
On the other hand, I've seen code where the primary game loop is in main and class functions are called from that loop.
Is there an advantage of just using main to call the first class function as in the code example above, as opposed to the primary game loop being in main and calling class functions from there?
Thanks,
Raptor
-
July 9th, 2012, 03:54 PM
#2
Re: A beginner's question on how main "should be" structured.
From a runtime perspective it doesn't matter.
If your code should be runnable on several platforms it might easier doing as in your example though. The most obvious thing I can come up with at the moment is that for a Windows application the entry function is WinMain instead of main. Having a bare minimal amount of the code in main minimize the amount of duplicated code.
Maybe it also can have some impact on the test code depending on the test framework.
-
July 9th, 2012, 07:20 PM
#3
Re: A beginner's question on how main "should be" structured.
Hi S_M_A,
If there's no compelling reason to do it either way, I guess I'll put the primary loop in main for small projects and call a class function for larger projects.
Thanks,
Raptor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|