jeudi 1 août 2019

Why doesn't any constructor get called?

class X {
public:
    X() {}
    X(const X&) {
    }
    X(X&&) {
    }
};

X func() { return X(); }

int main() {
    X x(func()); // which constructor for x?
}

I think that the move constructor must be called, but neither copy constructor nor move constructor gets called. Is this because of copy ellision?

Aucun commentaire:

Enregistrer un commentaire