Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix 13.16 #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

fix: fix 13.16 #833

wants to merge 1 commit into from

Conversation

Crazyokd
Copy link

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
Copy link

bestxmg commented Dec 17, 2024

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