#include <iostream> class X { public: int x; X(int x) : x(x) { std::cout << "X::X(int), x = " << x << '\n'; } X(const X& other) : x(other.x) { std::cout << "X::X(const X &), x = " << x << ", other.x = " << other.x << '\n'; } X &operator=(const X& other) { std::cout << "X::operator=(const X &), x = " << x << ", other.x = " << other.x << '\n'; if (&other == this) { return *this; } x = other.x; return *this; } ~X() { std::cout << "X::~X(int), x = " << x << '\n'; } }; X fun(X obiekt) { // Obiekt tymczasowy: return X(obiekt.x * 2); } int main() { std::cout << "obiekt\n"; X obiekt(5); std::cout << "przypisanie\n"; obiekt = 10; std::cout << "wywolanie funkcji\n"; fun(obiekt); std::cout << "wywolanie funkcji z obiektem tymczasowym\n"; obiekt = fun(X(30)); return 0; }
Standard input is empty
obiekt X::X(int), x = 5 przypisanie X::X(int), x = 10 X::operator=(const X &), x = 5, other.x = 10 X::~X(int), x = 10 wywolanie funkcji X::X(const X &), x = 10, other.x = 10 X::X(int), x = 20 X::~X(int), x = 20 X::~X(int), x = 10 wywolanie funkcji z obiektem tymczasowym X::X(int), x = 30 X::X(int), x = 60 X::operator=(const X &), x = 10, other.x = 60 X::~X(int), x = 60 X::~X(int), x = 30 X::~X(int), x = 60