Advertisement

Pure virtual classes

Started by May 12, 2000 08:59 AM
0 comments, last by Yanroy 24 years, 7 months ago
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;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

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.

Erik

This topic is closed to new replies.

Advertisement