Little help with constructors...
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++
_________________________________________"You're just jelous because the voices only talk to me"
Why were you told to do that? What do you need the constructor to do?
Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development
Why do you say it doesn''t work? A constructor is similar to a function; you should have no problems putting that in there.
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?
Am I making any sense?
_________________________________________"You're just jelous because the voices only talk to me"
Makes sense, but do you understand what a constructor is? There is no reason why you can''t put SRAND(time(NULL)) in one.
when I put
being the constructor in the class or
It gives me an error when I compile...
crapstable():{srand (time (NULL));}
being the constructor in the class or
crapstable():srand (time (NULL)){}
It gives me an error when I compile...
_________________________________________"You're just jelous because the voices only talk to me"
yeah you can''t do that. here''s how you do a constructor:
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
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
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.
Infuscare, sorry about that mate. Good luck with the game.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement