Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Test {
- public:
- Test(const int& value) : value_(value) {
- cout << "parameterized constructor for " << this << endl;
- }
- Test(const Test& other) : value_(other.value_) {
- cout << "copy constructor for " << this << endl;
- }
- Test& operator=(const Test& other) {
- if (this != &other) {
- value_ = other.value_;
- }
- cout << "operator = for Test for " << this << endl;
- return *this;
- }
- Test& operator=(const int& value) {
- value_ = value;
- cout << "operator = for " << this << endl;
- return *this;
- }
- friend ostream& operator<<(ostream& out, const Test& test);
- private:
- int value_ = 1;
- };
- ostream& operator<<(ostream& out, const Test& test) {
- out << test.value_;
- return out;
- }
- int func(int x) {
- return x * 2;
- }
- int main() {
- Test a(3); // слева именованный(lvalue) объект, справа временный объект(rvalue) типа int (целочисленный литерал)
- Test b(2); // слева именованный(lvalue) объект, справа временный объект(rvalue) типа int
- a = 3; // слева именованный (lvalue) объект, справа временный объект (rvalue) типа int
- a = 3 + 4; // слева именованный (lvalue) объект, справа временный объект (rvalue) - результат выражения
- a = func(5); // слева именованный (lvalue) объект, справа временный объект (rvalue) - результат работы функции
- a = b; // слева и справа именованные (lvalue) объекты
- cout << a << endl;
- cout << b << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement