Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Test {
- private:
- int g;
- public:
- Test() : g(0) {
- cout << "Default constructor\n";
- }
- Test(int x) : g(x) {
- cout << "Init int\n";
- }
- Test(const Test& t) : g(t.g) {
- cout << "Init test\n";
- }
- Test(Test&& t) : g(t.g) {
- cout << "Init rvalue\n";
- }
- Test& operator=(const Test& t) {
- cout << "Copy test\n";
- g = t.g;
- return *this;
- }
- Test operator+(const Test& t) const {
- cout << "Opeartor add\n";
- return Test(g + t.g);
- }
- ~Test() {
- cout << "Destroy\n";
- }
- };
- Test foo(Test&& A) {
- cout << "It is foo(Test &&)\n";
- return *(new Test(-1));
- }
- Test& foo(const Test& A) {
- cout << "It is foo(const Test &)\n";
- return *(new Test(-5));
- }
- void bar() {
- cout << "It is bar()\n";
- foo(Test(5));
- foo(Test(2) + Test(6));
- Test g = 7;
- foo(g + foo(g));
- }
- int main() {
- bar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement