Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I have Class A, that has a virtual method. (and implements it)
Class B inherits from Class A, but does not implement the virtual method.

I have a map of objects of class B.

I have a very long program, and it adds a lot of times objects to the map.

I run the program randomly, and once in about 4-5 runs, it crashed with a message of:
"::`vftable' (NULL:0)".

It is an unhandeled exception and I can't go back to the place it happened.

My guess is that the virtual table has been overwritten somehow, but I can't find when it happens (and as I said, it happens just once in 4-5 runs).

Is there a way I can find, using the debugger, the point and moment the virtual table is overridden?

Thanks
Posted
Updated 2-Dec-14 10:04am
v3
Comments
Fredrik Bornander 2-Dec-14 9:59am    
Are you doing anything silly with pointers and accidentally overwrite the vtable for some of your objects? Do you have any potential buffer-overruns?
Philippe Mori 2-Dec-14 19:18pm    
Also using deleted or uninitialized pointers can cause problems...
ThunderWiring 14-Dec-16 4:41am    
i am experiencing the same issue.
Have you found what might have caused the problem?

Quote:
Is there a way I can find, using the debugger, the point and moment the virtual table is overridden?
Most likely your code overwrites the vtable. If yoyu are using Visual Studio the Data Breakpoints[^] could interest you.
 
Share this answer
 
Comments
Maciej Los 2-Dec-14 13:23pm    
+5
CPallini 2-Dec-14 13:58pm    
Thank you Maciej!
First of all, it makes no sense to use a class with non-implemented virtual function. If this class is abstract, used only as a base class for some other classes, this is fine, but you should not instantiate it.

Now, there is no such concept as overriding of a virtual table. You override a function. Each class using virtual function, generally is associated with its individual virtual table, that's all. So, you cannot find "the point and moment the virtual table is overridden" because such point does not exist. Virtual table is formed during the compilation, linking and, ultimately, loading of the project (essentially, loading — because the virtual table is the object residing in your RAM). It always exists when your application is started to execute. A virtual table itself is a static object, even though it is used to achieve dynamic dispatching of the calls.

Instead, you need to run the application under the debugger, find out in what line the exception is throwing, then put a break point on that line and inspect the context before executing this line to find what's wrong. Not being able to reproduce the same problem in 100% of cases can be nasty, but this debugging problem should be solvable.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 2-Dec-14 11:09am    
5ed!
Sergey Alexandrovich Kryukov 2-Dec-14 11:15am    
Thank you, Maciej.
—SA
Richard MacCutchan 2-Dec-14 12:41pm    
He means overwite not override
Maciej Los 2-Dec-14 13:24pm    
A small detail... ;)
Richard MacCutchan 2-Dec-14 13:32pm    
Actually quite a large one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900