C
Christopher
My derived class assignment operator is not working. It never seems to
get the assignment done. I suspect I am not allowed to implement it
this way, but I am unsure why. Can someone explain what is happening
here?
---------------------------------------------------------
struct Base
{
Base & operator = (const Base & rhs);
int m_x;
};
struct Derived : public Base
{
Derived & operator = (const Derived & rhs);
};
-----------------------------------------------------------
Base & Base:perator = (const Base & rhs)
{
m_x = rhs.m_x;
}
Derived & Derived:perator = (const Derived & rhs)
{
static_cast<Base>(*this) = static_cast<Base>(rhs);
return *this;
}
I did this, because, currently, derived does not have any extra member
data when compared to base.
When it does, I thought I could handle them one by one after the
static cast / base assignment I did above.
I must be wrong?
get the assignment done. I suspect I am not allowed to implement it
this way, but I am unsure why. Can someone explain what is happening
here?
---------------------------------------------------------
struct Base
{
Base & operator = (const Base & rhs);
int m_x;
};
struct Derived : public Base
{
Derived & operator = (const Derived & rhs);
};
-----------------------------------------------------------
Base & Base:perator = (const Base & rhs)
{
m_x = rhs.m_x;
}
Derived & Derived:perator = (const Derived & rhs)
{
static_cast<Base>(*this) = static_cast<Base>(rhs);
return *this;
}
I did this, because, currently, derived does not have any extra member
data when compared to base.
When it does, I thought I could handle them one by one after the
static cast / base assignment I did above.
I must be wrong?