multiple inheritance - vtable issue

A

Anuj P Shah

Hi,

I am using multiple implementation inheritance in one of my designs, and it
seems i am having some kind of a vtable problem when accessing functions.

The problem is like so:

class E inherits from class C and D, and C inherits from B, A. Another
class F stores pointers to instances of type A in a STL map. Now I am
storing pointers to type E in F (automatic upcasting). Another class G uses
F to get the pointers of class E and use them for making certain function
calls. My problem is that I am not able to use the pointer for any function
calls; there is a runtime error (an access violation). There is no
compilation error. But the debug window is able to resolve the pointer
without problems. I can static_cast the pointer into other types in the
hierarcy and get the pointers for those other types, but again there is a
runtime error when accessing them. I tried dynamic_cast but it failed at
runtime. If I use class qualifier when accessing a function using the
pointer, there is no error. Ofcourse that is not useful, because then I
have no advantage of the class heirarchy (polymorphism). These symptoms
make me think that the vtable has some kind of screw up or confusion. Can
anybody guess, what might be the sources of this problem?

Thanks,

Anuj
 
M

mlimber

Anuj said:
Hi,

I am using multiple implementation inheritance in one of my designs, and it
seems i am having some kind of a vtable problem when accessing functions.

The problem is like so:

class E inherits from class C and D, and C inherits from B, A. Another
class F stores pointers to instances of type A in a STL map. Now I am
storing pointers to type E in F (automatic upcasting). Another class G uses
F to get the pointers of class E and use them for making certain function
calls. My problem is that I am not able to use the pointer for any function
calls; there is a runtime error (an access violation). There is no
compilation error. But the debug window is able to resolve the pointer
without problems. I can static_cast the pointer into other types in the
hierarcy and get the pointers for those other types, but again there is a
runtime error when accessing them. I tried dynamic_cast but it failed at
runtime. If I use class qualifier when accessing a function using the
pointer, there is no error. Ofcourse that is not useful, because then I
have no advantage of the class heirarchy (polymorphism). These symptoms
make me think that the vtable has some kind of screw up or confusion. Can
anybody guess, what might be the sources of this problem?

Thanks,

Anuj

Please post a complete but minimal code sample that demonstrates the
problem. See the FAQ for guidelines:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

Cheers! --M
 
T

TIT

Anuj P Shah sade:
Hi,

I am using multiple implementation inheritance in one of my designs, and it
seems i am having some kind of a vtable problem when accessing functions.

The problem is like so:

class E inherits from class C and D, and C inherits from B, A. Another
class F stores pointers to instances of type A in a STL map. Now I am
storing pointers to type E in F (automatic upcasting). Another class G uses
F to get the pointers of class E and use them for making certain function
calls.

What function calls? malloc()?
My problem is that I am not able to use the pointer for any function
calls; there is a runtime error (an access violation). There is no
compilation error. But the debug window is able to resolve the pointer
without problems. I can static_cast the pointer into other types in the
hierarcy and get the pointers for those other types, but again there is a
runtime error when accessing them. I tried dynamic_cast but it failed at
runtime. If I use class qualifier when accessing a function using the
pointer, there is no error. Ofcourse that is not useful, because then I
have no advantage of the class heirarchy (polymorphism). These symptoms
make me think that the vtable has some kind of screw up or confusion. Can
anybody guess, what might be the sources of this problem?

Yes, the symptoms! Uh?
Ah, you mean that you blame the vtable for your corrupt code?

TIT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,296
Latest member
HeikeHolli

Latest Threads

Top