dimanche 27 octobre 2019

When does the body run with automatically assigned variables in constructors in C++?

I have doubts on how the constructor's body works in case of initialization lists; if the value passed by the constructor are not admitted value and an exception needs to be thrown, is it correct to do something like this?

Foo(int a_) : a(a_) {
  if (a>0)
    throw std::invalid_argument( "positive value!");
};

I am having doubt on how this is evaluated, in case of more complex situations. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire