level 13
狗gou富贵
楼主
#include <iostream>
using namespace std;
class A {
int x;
public:
A(int a = 0, int b = 2) :x(a) {}
A &operator=(A& o) {
x = o.x;
cout << "In A=(A&),x=" << x << endl;
return *this;
}
int getx() { return x; }
A& operator=(A &&o) = default;
};
class B :public A {
int y;
public:
B(int a = 0, int b = 0) :A(a), y(b) {}
B& operator =(B& o) {
A::operator=(o);
cout << "In B=(B&),x=" << getx() << "\ty=" << y << endl;
return *this;
}
};
int main() {
B b, b1(1, 2);
b = b1;
b1 = std::move(b);
}
2018年05月03日 09点05分
1
using namespace std;
class A {
int x;
public:
A(int a = 0, int b = 2) :x(a) {}
A &operator=(A& o) {
x = o.x;
cout << "In A=(A&),x=" << x << endl;
return *this;
}
int getx() { return x; }
A& operator=(A &&o) = default;
};
class B :public A {
int y;
public:
B(int a = 0, int b = 0) :A(a), y(b) {}
B& operator =(B& o) {
A::operator=(o);
cout << "In B=(B&),x=" << getx() << "\ty=" << y << endl;
return *this;
}
};
int main() {
B b, b1(1, 2);
b = b1;
b1 = std::move(b);
}