I know the standard has an exception about extending the lifetime of temporaries that basically says binding a const reference in a constructor won't extend the lifetime, but does this also apply to literals? For example:
class C {
private:
const int& ref;
public:
C(const int& in)
: ref{in}
{ }
};
If I had a function returning an object of this type
C f() {
C c(2);
return c;
}
Would the value of c.ref
be undefined in the caller if I know it's bound to a literal?
Aucun commentaire:
Enregistrer un commentaire