Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- static size_t counter = 0;
- using namespace std;
- class Number {
- private:
- int a_;
- public:
- Number() {
- cout << "Default Ctor"s << endl;
- cout << "at " << this << endl;
- ++counter;
- }
- Number(int num)
- : a_(num)
- {
- cout << "Ctor(int)"s << endl;
- cout << "at " << this << endl;
- ++counter;
- }
- Number(const Number& other)
- : a_(other.a_)
- {
- cout << "Copy Ctor"s << endl;
- cout << "at " << this << endl;
- cout << "other " << this << endl;
- ++counter;
- }
- ~Number() {
- cout << "Dtor"s << endl;
- cout << "at " << this << endl;
- ++counter;
- }
- Number& operator=(const Number& other) {
- a_ = other.a_;
- cout << "Op="s << endl;
- cout << "this op= " << this << endl;
- cout << "other " << &other << endl;
- ++counter;
- return *this;
- }
- Number operator+(const Number& second) {
- cout << "Op+" << endl;
- cout << "this op+ " << this << endl;
- cout << "second " << &second << endl;
- Number tmp_num(a_ + second.a_);
- cout << "tmp_num " << &tmp_num << endl;
- ++counter;
- return a_ + second.a_;
- }
- };
- int main() {
- Number a(1), b(1), c;
- c = a + b;
- cout << "End of calculations"s << endl;
- cout << counter << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement