Jump to content
  • Advertisement
Sign in to follow this  

This topic is 4810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Guest Anonymous Poster
The only piece of evidence i can find, that would suggest it is dodgy, is that it states that main() has implementation defined linkage in one section, and then in another it states that a function first declared as a friend in a class is given external linkage. Not that conclusive though.

Share this post


Link to post
Share on other sites
Quote:
Original post by Magmai Kai Holmlor
Yeah it is. You're not allowed to overload main. (And it must return an int.)


I don't know about the latest compilers but I remember Turbo C++ allowing me to go: void main() (although nowadays I return an int for debugging purposes)

That would be interesting to see if it works under VC++ 7

Share this post


Link to post
Share on other sites
Quote:
Original post by Talib
I don't know about the latest compilers but I remember Turbo C++ allowing me to go: void main() (although nowadays I return an int for debugging purposes)

VC still allows void main as well, but its not supposed to. Seems like a silly requirement to me, but I'm sure they've got some logic behind it.

.NET 2003 does support main being a friend function, if I understand the question correctly. Obviously, this doesn't mean its actually standard compliant code.

#include <iostream>
using std::cout;
using std::endl;

class FriendlyMain
{
int somePrivateVariable;
friend int main()
{
FriendlyMain x;
x.somePrivateVariable = 10;
cout << x.somePrivateVariable << endl;
}
};


That particular implementation yields

c:\Code\Test\Test.cpp(35) : warning C4008: 'main' : 'inline' attribute ignored

But that can be gotten rid of by moving the implementation out of the class.

CM

Share this post


Link to post
Share on other sites
I don't see anything against making main a friend function. It is illegal, however, to call main.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!