¿¹Á¦

#include "BaseClass.h"

struct ST
{
int a;
char c;
};
   
class Derived : Base{

public:
Derived(int newx, int newy);
Derived& operator=(const Derived& rhs);

private:
int x;
int y;

ST myStructure;
};

DerivedDerived::operator=(const Derived& rightValue)
{
if(this == &rightValue){
return *this;
}

x = rightValue.x;
y = rightValue.y;

myStructure.a = rightValue.myStructure.a;
myStructure.c = rightValue.myStructure.c;

return *this;
}

¼Ö·ç¼Ç
±âº» Ŭ·¡½ºÀÇ ´ëÀÔ »ý¼ºÀÚµµ ÇÔ²² È£ÃâÇϽʽÿÀ.

#include "BaseClass.h"

struct ST
{
int a;
char c;
};
   
class Derived : Base{

public:
Derived(int newx, int newy);
Derived& operator=(const Derived& rhs);

private:
int x;
int y;

ST myStructure;
};

DerivedDerived::operator=(const Derived& rightValue)
{
if(this == &rightValue){
return *this;
}
   
static_cast<Base&>(*this) = rightValue;

x = rightValue.x;
y = rightValue.y;

myStructure.a = rightValue.myStructure.a;
myStructure.c = rightValue.myStructure.c;

return *this;
}