Archived

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

Oxyd

Pure virtual function call

Recommended Posts

Oxyd    1157
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
Oxyd    1157
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
Painless    126
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