Jump to content
  • Advertisement


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


Pure virtual classes

This topic is 6923 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

If a class is all pure virtual functions, does it still have a V-Table? It would make sense for it to have one... it isn''t needed, is it? I was wondering because I have heard (many times) that when using inheritance, the V-Table sucks up memory like some kind of vacuum cleaner. I thought maybe having a base class with all pure virtual functions could get around that. The functions that I have now are mostly like the following, so it wouldn''t make a difference if they were pure virtual:
virtual void SomeFunction() {;}
That would be inside a class, btw --------------------

You are not a real programmer until you end all your sentences with semicolons;


Visit the ROAD Programming Website for more programming help.

Share this post

Link to post
Share on other sites
I guess that with pure virtual functions, you mean (virtual) abstract functions? There''s a difference between virtual void SomeFunction() { ; } and virtual void SomeFunction() = 0; The latter makes the class that contains that method a abstract base class which can''t be instantiated directly. Only sub classes can be instantiated. However, a pointer to an abstract base class can hold the address of any subclass of it.

The vtable only lists the virtual function of a class, and is necessary to support polymorphism. So if you have a base class with all virtual functions, then you''d still have a vtable, I think.

I don''t know exactly how much memory is ''sucked up'' by inheritance, but I think you shouldn''t worry too much about it. It isn''t a very high price to pay for what you get in return.


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!