Hi I had a question, why do I never see people use if statements or other logic statements inside classes?, do classes not allow this?.
Thanks .
A basic C++ question
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
A basic C++ question
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
That's what preprocessor commands like #ifdef and #ifndef are for (and no, you can't have logic inside of your class definition unless it's inside a function definition)
-wyrmmage
-wyrmmage
Worlds at War (Current Project) - http://www.awkward-games.com
Ganadu'r, The Eternal Sage (Other Current Project) - http://rpg.naget.com
Ganadu'r, The Eternal Sage (Other Current Project) - http://rpg.naget.com
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Re: A basic C++ question
Presumably you mean inside a class declaration but outside any function definition?3DModelerMan wrote:Hi I had a question, why do I never see people use if statements or other logic statements inside classes?, do classes not allow this?.
Thanks .
It only makes sense to have executable code inside a function, because otherwise there's no way to call and run the code. So you don't see any code outside of a function (whether global, class static or class instance).
Code: Select all
class Foo
{
public:
printf("At what point in your program execution would you expect this code to ever be run?");
Foo()
{
printf("If you want code that's run when an instance is created, put it in the constructor.");
}
};
printf("Or for that matter, how would you run this global code?");
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
okay
Thanks, I guess I should have searched a little more, but I was just wondering why I had'nt seen any.
Thanks .
Thanks .
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar