Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Access to protected member functions?

0 views
Skip to first unread message

Alain Dekker

unread,
Jun 26, 2001, 6:04:07 AM6/26/01
to
This is a question that is purely C++-related. I have the following class:

class CTest
{
public:
CTest(){m_nNumber = 5;};
~CTest(){};
void SetNumber(int nNew){m_nNumber = nNew;};

protected:
int m_nNumber
}

Is there any way to get access to that protected member variable WITHOUT
adding a public accessor variable such as "int GetNumber(){return
m_nNumber;};"? For reasons I cannot go into, I cannot change the above class
to add this fucntion.

I've tried this sneaky solution:
class CTry : CTest
{
public:
CTry(){};
~CTry(){};
int GetNumber(){return m_nNumber;};
}

But all I ever get is a the "5" set by the constructor. Is it possible
somehow to use a copy constructor for this.

Any replies much appreicated,

Regards
Alain


0 new messages