lundi 9 octobre 2017

C++ Why was the copy constructor called?

class A {
public:
    A() {}
    A(const A& a) { cout << "A::A(A&)" << endl; }
};

class B {
public:
    explicit B(A aa) {}
};

int main() {
    A a;
    B b(a);
    return 0;
}

Why does it print "A::A(A&)"?

When was the copy constructor for "A" called? And if the code calls the copy constructor, why can I remove the copy constructor without creating a compilation error?

Aucun commentaire:

Enregistrer un commentaire