Pure Virtual Functions
BlackSoldierB
Posts: 45
I was adding some more structure to my program and something weird occurred.
First i added a interface for my "Test" (rather small) class and create some (also small) classes who derived from the interface.
Everything is going fine, but when i added a interface for an other (somewhat large) class the program didn't fit in the memory anymore (overflow by 32K).
After replacing the pure virtual functions with a "normal" virtual function, and adding an empty implementation, everything fits inside the memory again.
Putting the "somewhat large class" implementation into the header produces the same result.
I am curious why the memory usage grows with that much memory. My guess is that the compiler optimizes "something" for more than 32K.
Anyone experienced this before?
First i added a interface for my "Test" (rather small) class and create some (also small) classes who derived from the interface.
Everything is going fine, but when i added a interface for an other (somewhat large) class the program didn't fit in the memory anymore (overflow by 32K).
After replacing the pure virtual functions with a "normal" virtual function, and adding an empty implementation, everything fits inside the memory again.
Putting the "somewhat large class" implementation into the header produces the same result.
I am curious why the memory usage grows with that much memory. My guess is that the compiler optimizes "something" for more than 32K.
Anyone experienced this before?
Comments
http://forums.parallax.com/showthread.php/150860-Pure-Virtual-Functions-Cause-Instant-Code-Bloat?highlight=virtual+function
You have to add this to the main program:
So obvious in hindsight! I'll bet you feel like a right noob!
That's why I love C++ so much, and GCC in particular
I haven't tested this, but giving the pure virtual function(s) an implementation should also fix this problem (yes, you can do this).