如何在结构体内写一个函数,使结构体变量b赋值给a。
(调用方式:a.asmt(b);//b赋给a)
struct A
{
void asmt(A &b)
{
*this = b;
}
};
struct MyStruct {
int x;
int y;
void asmt(const MyStruct &other) {
x = other.x;
y = other.y;
}
};
MyStruct a, b;
a.asmt(b);