Jump to content
  • Advertisement
Sign in to follow this  
makingroulette

virtual static variables?

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

I have a class called ListBet, and I want the function in it - CheckNumbers - to access static variables declared in classes that will derive from ListBet class ListBet { protected: bool CheckNumbers(char numberDrawn); }; I want it to be able to access the static variables for example in a class such as this: class InsideBet : public ListBet { private: static char m_InsideBetOdds; static char m_NumberOfNumbers; static float m_Width; static float m_Height; } I don't want to put these static variables in ListBet because many classes will derive from ListBet, and each will have different values for the static variables. This way I would only have to write the CheckNumbers() function once. Thanks in advance for your help if you need more clarification do not hesitate to ask [Edited by - makingroulette on May 29, 2005 9:47:04 AM]

Share this post


Link to post
Share on other sites
Advertisement
Is this acceptable? Im not realy sure what you want.
class ListBet
{
protected:
virtual bool CheckNumbers(char numberDrawn)=0;
};

template<typename T>
class ListBetImpl : public ListBet
{
protected:
virtual bool CheckNumbers(char numberDrawn)
{
// Put something more useful here.
return (T::m_Width * T::m_Height) < 16.0f;
}
};

class InsideBet : public ListBetImpl<InsideBet>
{
private:
friend ListBetImpl; // May need to be templated. I cant remember.
static char m_InsideBetOdds;
static char m_NumberOfNumbers;
static float m_Width;
static float m_Height;
}




edit: fixed code

Share this post


Link to post
Share on other sites
Thanks for that, it looks like it does what i wanted it to do.

I have seen other approaches to this kind of problem that were very messey, yours is the best

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!