A basic C++ question

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

A basic C++ question

Post by 3DModelerMan »

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 :D .
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
jaeg
Posts: 52
Joined: Thu Jun 28, 2007 11:20 pm

Post by jaeg »

I believe that those statements can only be in class functions.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I really can't take this thread as even remotely serious. The answer to your question, 3DModelerMan, lies here.
TheQuestion = 2B || !2B
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

Halifax wrote:I really can't take this thread as even remotely serious. The answer to your question, 3DModelerMan, lies here.
Most certainly the answer to all your past, present, and future questions have, and will lay here.
wyrmmage
Posts: 204
Joined: Sun Mar 16, 2008 3:12 am
Contact:

Post by wyrmmage »

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
Worlds at War (Current Project) - http://www.awkward-games.com
Ganadu'r, The Eternal Sage (Other Current Project) - http://rpg.naget.com
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

zeno60 wrote:
Halifax wrote:I really can't take this thread as even remotely serious. The answer to your question, 3DModelerMan, lies here.
Most certainly the answer to all your past, present, and future questions have, and will lay here.
Haha, yes, I stand corrected.
TheQuestion = 2B || !2B
rogerborg
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

Post by rogerborg »

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 :D .
Presumably you mean inside a class declaration but outside any function definition?

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
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

Post by kingdutch »

That's basicly it, for more info on classes let's try our friend Google :D
*click*
if (msg.getRubbishFactor() > rubbishLimit) { ignorePost(); cout << how it should be done << "\n"; }
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

okay

Post by 3DModelerMan »

Thanks, I guess I should have searched a little more, but I was just wondering why I had'nt seen any.
Thanks :D .
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Post Reply