Archived

This topic is now archived and is closed to further replies.

Little help with constructors...

This topic is 5534 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

Some1 told me in another thread that I should put SRAND(time(NULL)) in a constructor... how do i do that, I know how to put variables in there but just sticking that in the constructor doesn''t work. Ps. Yes I am relatively new to programming in C++

Share this post


Link to post
Share on other sites
I had a gambling game (don''t ask) in which i rolled a dice, and some1 told me that I should put that in the constructor of the class instead of making it do that every time it goes through the member function.

Am I making any sense?

Share this post


Link to post
Share on other sites
yeah you can''t do that. here''s how you do a constructor:


class CrapsTable {
public:
CrapsTable() {
SRAND(time(NULL));
}

};



the : operator after the fctn is usually used to call a base class constructor with certain parameters. you should re-read the classes and constructors/destructors of you C++ book. it seems you are unclear what/how to use them

-me

Share this post


Link to post
Share on other sites
Hey guys. That someone was me, a few days ago. I should have gone over constructors then. Thanks for explaining things.

Infuscare, sorry about that mate. Good luck with the game.

Share this post


Link to post
Share on other sites