vendredi 5 juillet 2019

Why the copy constructor is called when I add a different object which is an argument in copy constructor?

I don't understand why the copy constructor is called while i am adding e to c.

struct A {};
struct B {
    B() { std :: cout << "B Constructor" << std :: endl; }
    B(const A&) { std :: cout << "B Copy" << std :: endl;}
    const B operator +(const B& arg);
};

const B B::operator +(const B& arg) {
    std :: cout << "+" << std :: endl;
    return B();
}

int main() {
    B c;
    A e;
    c + e;
}

Aucun commentaire:

Enregistrer un commentaire