Skip to content

fix: fix 13.16#833

Open
Crazyokd wants to merge 1 commit into
Mooophy:masterfrom
Crazyokd:patch-1
Open

fix: fix 13.16#833
Crazyokd wants to merge 1 commit into
Mooophy:masterfrom
Crazyokd:patch-1

Conversation

@Crazyokd

Copy link
Copy Markdown

you can verify it by execute code below:

#include <iostream>

using namespace std;

class X {
        public:
                int mysn = 0;
                X() {}
                X(const X&orig): mysn(orig.mysn + 1) {
                        cout << "copy constructor " << (orig.mysn + 1) << endl;
                }
};

void f (const X &x) {
        cout << x.mysn << endl;
}

int main() {
        X a, b = a, c = b;
        f(a);
        f(b);
        f(c);
        return 0;
}

@bestxmg

bestxmg commented Dec 17, 2024

Copy link
Copy Markdown

I have the same doubt.

numbered a, b = a, c = b;
In my opinion, the code above will call the copy constructor (both on b and c) but not the assignment operator. Now that the copy constructor has been executed, the output should not be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants