samedi 27 janvier 2018

Calling default constructor in return statement

Suppose I have a trivial class:

class Temp {
    private:
        int vals;
    public:
        Temp();
        Temp(int x):vals(x);
        Temp& someFunc(const Temp& t);
};

And say someFunc has a condition where it would call the following:

return Temp null_t; // not allowed for some reason

And yet, this works (as it is expected to):

Temp null_t;
return null_t;

Why can I not call the default constructor in the same line as the return?

Aucun commentaire:

Enregistrer un commentaire