Sollicitatievraag bij Weta Digital

What should not be in a constructor?

Antwoorden op sollicitatievragen

Anoniem

1 sep 2015

I answered several things that should not be in, apparently the answer should have been any virtual functions.

Anoniem

26 feb 2017

Hmm, the first answer that came to mind was: two new statements, without a try-catch around the second that deletes the first. There are probably many answers to such a vague question; it is indeed unintuitive to programmers coming from e.g. C#, that virtual function calls in the constructor wouldn't call overrides (that's called dynamic binding, C++ doesn't have it), but it is almost as unintuitive that your destructor which tries to delete both objects would not be called at all, if the constructor throws an exception.