Archived

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

Pure virtual function call

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

I wrote a program and tryied to run it. It immediately crashed and on my cerr output was: "Pure virtual method called". I just glared - how is it possible to call pure virtual function? I thought, that the linker must reject all bindings to virtual functions...? Oxyd --- - Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t. - Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
Likely your constructor is trying to call something pure virtual, or calls something which ends up calling something that''s pure virtual, which is only defined in a subclass. When the first constructor runs, the object isn''t really set up completely. The Vtable actually changes before running each constructor. If you manage to call a virtual function before the subclass constructor runs, it won''t be doing what you expect.

Share this post


Link to post
Share on other sites
As far as I know, in constructors there''s no late binding. Just early binding - thus calling virtual function in constructor ends up with calling local version. And the linker should not link application where is binding (early) to pure virtual function...

Btw - debugging shows up that it occurs in delete call - thus it is probably in destructor in which (like in constructors) there''s only early binding.

Oxyd

---
- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
I''ve had that error too, I think it was the result of some misuse of multiple inheritance. Check that all classes that need virtual inheritance are using it.

Share this post


Link to post
Share on other sites