vendredi 24 novembre 2017

C++, reference parameter default value allowed in constructor

In .h file

class X{
private:
  std::chrono::minutes A;
public:
  X(std::chrono::minutes& a = std::chrono::minutes {5});
}

In .CPP file

X::X(std::chrono::minutes& a): A(a){}

Can std::chrono::minutes {5} go out of scope before getting assigned to A

for example,

void main()
{
   X x;
}

Is it guaranteed that object x will have member A with value std::chrono::minutes {5} always?

Aucun commentaire:

Enregistrer un commentaire