Jump to content
  • Advertisement

Archived

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

Infuscare

Little help with constructors...

This topic is 5722 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
Advertisement
Why do you say it doesn''t work? A constructor is similar to a function; you should have no problems putting that in there.

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
Makes sense, but do you understand what a constructor is? There is no reason why you can''t put SRAND(time(NULL)) in one.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!