R
Rob Richardson
Greetings!
Consider the following:
class CBase
{
public:
CBase();
virtual ~CBase();
protected:
int m_protected;
};
class CDerived : public CBase
{
public:
void TestBase(const CBase& other);
void TestDerived(const CDerived& other);
};
CBase::CBase()
{
m_protected = 1;
}
CBase::~CBase()
{
}
void CDerived::TestBase(const CBase& other)
{
int fromMe = m_protected;
int fromTheOther = other.m_protected; // Error: Can't access
protected member
//
declared in CBase
}
void CDerived::TestDerived(const CDerived& other)
{
int fromMe = m_protected;
int fromTheOther = other.m_protected; // No error
}
When this is compiled in MS Visual C++, the indicated error is thrown
in TestBase(), but TestDerived() does not have a problem. I would
have thought that either I'd get an error in both places or I would
not have gotten any areas. Why am I only getting one error?
Thank you very much.
Rob Richardson
Consider the following:
class CBase
{
public:
CBase();
virtual ~CBase();
protected:
int m_protected;
};
class CDerived : public CBase
{
public:
void TestBase(const CBase& other);
void TestDerived(const CDerived& other);
};
CBase::CBase()
{
m_protected = 1;
}
CBase::~CBase()
{
}
void CDerived::TestBase(const CBase& other)
{
int fromMe = m_protected;
int fromTheOther = other.m_protected; // Error: Can't access
protected member
//
declared in CBase
}
void CDerived::TestDerived(const CDerived& other)
{
int fromMe = m_protected;
int fromTheOther = other.m_protected; // No error
}
When this is compiled in MS Visual C++, the indicated error is thrown
in TestBase(), but TestDerived() does not have a problem. I would
have thought that either I'd get an error in both places or I would
not have gotten any areas. Why am I only getting one error?
Thank you very much.
Rob Richardson