I have a class that is inherited from an abstract base class.
class CStateBase
{
friend class CApplication;
friend class CGraphics;
virtual int Update() =0;
};
class CStateTitle: private CStateBase
{
friend class CApplication;
friend class CGraphics;
CApplication *f_App;
int m_iR;
int Update();
CStateTitle(CApplication *App);
~CStateTitle();
};
In a method of another class, CStateTitle is dynamically allocated into a CStateBase pointer. However, if I use that pointer to try and access the variable int m_iR, the compiler looks for the variable in CStateBase and therefore makes an error. If I could declare virtual int m_iR in the base class I would think it would work fine, but for some reason it’s not letting me declare virtual data members. What is the recommended way to get around this problem? Thanks for any help.
The best way is to abstract the access of
m_iRinto some virtual function.Another choice would be to move
m_iRfromCStateTitleintoCStateBase. This only makes sense if every class needs anm_iR.A last resort would be to do a dynamic cast: