Archived

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

Infuscare

Little help with constructors...

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
when I put


  

crapstable():
{srand (time (NULL));}



being the constructor in the class or


  

crapstable():srand (time (NULL))
{}



It gives me an error when I compile...

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