🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Whining

Published April 22, 2007
Advertisement
Stupid C++ and stupid classes not being able to call virtual members from constructors. Stupid annoying stupid rrrghhh stupid hate hate hate DIE.


That is all.
Previous Entry My Narcotics Addiction
Next Entry Haha creativity.
0 likes 3 comments

Comments

Julian90
I know your probally whining for a reason but thats one of the few things where I think c++ took the logical choice, if you could call virtual functions from in the constructor then you might call a virtual function from a base class which acesses the members of a derived class before they are initialized so its "cant call them" or "potentially undefined behaviour if you call them", I know which I prefer ;).
April 22, 2007 06:49 AM
ApochPiQ
Of course it's logical. The only way to get around it would be to force the compilers to basically do two-phase construction transparently (i.e. init the vtable first and then call the normal constructors) which introduces all kinds of nasty problems of its own, and violates the well-known C++ design policy of "you don't pay for what you don't use."

The problem is it ruins a few designs that would otherwise be very elegant, especially when it comes to building classes in the RAII style. Of course, one could make a very good argument that anyone looking for ease of elegant design should steer well clear of C++ in the first place.
April 22, 2007 06:49 PM
Julian90
ok then, I guess if you really need it you could get the same effect by passing a member function pointer to the class constructor and hide it from users by setting it to a default value, its a bit of extra work since you have to pass the new pointer to the base class in each derived class constructor but its better then nothing.
April 23, 2007 02:26 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement