在这段代码中,为什么我可以访问对象的私有成员而没有编译错误?
class Cents
{
private:
int m_nCents;
public:
Cents(int nCents=0)
{
m_nCents = nCents;
}
// Copy constructor
Cents(const Cents &cSource)
{
m_nCents = cSource.m_nCents;
}
Cents& operator= (const Cents &cSource);
};
Cents& Cents::operator= (const Cents &cSource)
{
cSource.m_nCents是私有的,为什么我可以做以下操作:
m_nCents = cSource.m_nCents;
// return the existing object
return *this;
}