Jump to content
  • Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


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.
Sign in to follow this  


Recommended Comments

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 ;).

Share this comment

Link to comment
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.

Share this comment

Link to comment
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.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!