Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

_Jax_

problem with virtual functions

This topic is 6106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, here''s what I do: I created a Window class to do all the Microsoft stuff in my app. It has a WNDPROC which calls event handlers from that class (like OnResize, OnActivate,..). I thought It might be a good idea to keep that as an abstact base class, so that''s what I did. I made all the event handlers abstract (like this: virtual void OnResize()=0 and implemented those in class, derived from that base class, which is actually my program. So here''s my problem: some of the Event handlers (like OnInit and OnResize) needed to be called in the base class''s constructor. But it somehow doesn''t call the new functions in the class I actually use, but in the abstact base class. This only happens in the calls from the constructor..I cannot explain that. Is that a bug in the compiler or what?

Share this post


Link to post
Share on other sites
Advertisement
That''s how it''s supposed to work. When the constructor runs the object is by definition not completely constructed yet. A constructor can''t access any method in a derived class, because the constructor of that derived class hasn''t been run yet, and the vtable hasn''t been setup with the derived methods.

Perhaps you should defer any advanced initialization to an Init-method or something.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!