I have two classes, one is the base class of the other. I would like call “operator = “ from the base class in addition to the new “operator =”. I know I am missing something simple, but I don’t know what.
class CAge
{
public:
CAge();
~CAge();
Cage & operator = (CAge &catmp)
{
SetAge(catmp.GetAge());
}
void SetAge( int iAge) {m_iAge = iAge;}
int GetAge() { return iAge;}
private:
int m_iAge;
}
class CPerson : public CAge
{
CPerson();
~CPerson();
CPerson & operator = (CPerson &cptmp)
{
SetName(cptmp.GetName());
}
void SetName(CString SName) {m_SName = SName;}
CString GetName() { return SName;}
private:
Cstring SName;
}
so
main ()
{
CPerson P1, P2;
P2.SetAge(1);
P2.SetName("A Name"
;
P1 = P2;
int iAge = P1.GetAge();
}
I know, in CPerson, I can add
SetAge(cptmp.GetAge());
but I thought there was automatic way. Thanks!!!
class CAge
{
public:
CAge();
~CAge();
Cage & operator = (CAge &catmp)
{
SetAge(catmp.GetAge());
}
void SetAge( int iAge) {m_iAge = iAge;}
int GetAge() { return iAge;}
private:
int m_iAge;
}
class CPerson : public CAge
{
CPerson();
~CPerson();
CPerson & operator = (CPerson &cptmp)
{
SetName(cptmp.GetName());
}
void SetName(CString SName) {m_SName = SName;}
CString GetName() { return SName;}
private:
Cstring SName;
}
so
main ()
{
CPerson P1, P2;
P2.SetAge(1);
P2.SetName("A Name"
P1 = P2;
int iAge = P1.GetAge();
}
I know, in CPerson, I can add
SetAge(cptmp.GetAge());
but I thought there was automatic way. Thanks!!!