Sign in to follow this  
makingroulette

virtual static variables?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this