Jul 24, 2009 at 2:37pm UTC
1. Is it bad practice to call member functions from inside the constructor?
2. Is it bad practice to call member functions from inside other member functions?
Jul 24, 2009 at 3:01pm UTC
Ok sorry, I thought I tried that and got an error but I just re-did it and it was fine. Thanks both of you!
Jul 24, 2009 at 3:30pm UTC
To clarify one of the original questions.
1. It is fine to call non-virtual methods from the constructor.
Jul 24, 2009 at 3:49pm UTC
Yeah that's what I meant, I haven't covered virtual-methods yet. For when I do though, why can't/shouldn't you call virtual methods?
Jul 24, 2009 at 3:57pm UTC
Because the vtable isn't built completely by the time the constructor is called.
On a similar note, the same problem happens with virtual functions and destructors.
Basically you shouldn't/can't call members of derived classes from the parent's ctor/dtor.