vtordisp on|off 
Author Message
 vtordisp on|off

Hi all,

    I'm doing a model for a problem here at work and we're evaluating using
multiple inheritance for one of our larger architectual insolvencies.  We
had originally gone the route, but had problems typecasting pointers with
virtual base classes.  So,

class A : virtual public B, public C;
class D : public A, virtual public B;
class E : public D;

would have problems trying to convert E* to, say, D* or A* or C*.  The
memory just wasn't in the expected places.  Is this something that adjusting
the pragma vtordisp would help to solve?  Would we need to use a better tool
than classic typecasting, such as reinterpret_cast<>?  And could someone
translate the MSDN entires on vtordisp into english or give an example of
when to use it?  That would be rather awesome....  :)

Thanks!
-Dale



Sat, 16 Apr 2005 05:48:18 GMT  
 vtordisp on|off

Quote:
> Hi all,

>     I'm doing a model for a problem here at work and we're evaluating
using
> multiple inheritance for one of our larger architectual insolvencies.  We
> had originally gone the route, but had problems typecasting pointers with
> virtual base classes.  So,

> class A : virtual public B, public C;
> class D : public A, virtual public B;
> class E : public D;

> would have problems trying to convert E* to, say, D* or A* or C*.  The
> memory just wasn't in the expected places.  Is this something that
adjusting
> the pragma vtordisp would help to solve?  Would we need to use a better
tool
> than classic typecasting, such as reinterpret_cast<>?  And could someone
> translate the MSDN entires on vtordisp into english or give an example of
> when to use it?  That would be rather awesome....  :)

All of the conversions you mentiond (E* to D*, A*, C*) are valid
static_casts<> (assuming you defined classes B and C somewhere), and a
C-style cast should produce a static_cast in all such cases.  Perhaps you
could elaborate on "the memory just wasn't in the expected places" - how do
you know?

The gist of vtordisp is this:  if vtordisp is on (/vd1, the default), then
the compiler implements virutal functions the way they're specified in the
C++ spec.  If vtordisp is off (/vd0), then virtual function calls from the
constructor of destructor of a class with virtual bases will not work
correctly (most likely, the program will crash).  Use /vd0 or #pragma
vtordisp(off) only if you know absolutely that no class with virtual bases
makes calls to virtual member functions from the constructor or destructor.

-cd



Sat, 16 Apr 2005 07:30:04 GMT  
 vtordisp on|off
Aha, thanks for the vtordisp explanation.  Helps out quite a bit.

The memory...  this was a few months back, but now that I think about it, it
seems like our problem was in copy constructors..  I think the person who
originally coded them failed to remember that vtables exist for polymorphic
classes...  brain fart on my part, disregard :)

Thanks again,
-Dale



Quote:


> > Hi all,

> >     I'm doing a model for a problem here at work and we're evaluating
> using
> > multiple inheritance for one of our larger architectual insolvencies.
We
> > had originally gone the route, but had problems typecasting pointers
with
> > virtual base classes.  So,

> > class A : virtual public B, public C;
> > class D : public A, virtual public B;
> > class E : public D;

> > would have problems trying to convert E* to, say, D* or A* or C*.  The
> > memory just wasn't in the expected places.  Is this something that
> adjusting
> > the pragma vtordisp would help to solve?  Would we need to use a better
> tool
> > than classic typecasting, such as reinterpret_cast<>?  And could someone
> > translate the MSDN entires on vtordisp into english or give an example
of
> > when to use it?  That would be rather awesome....  :)

> All of the conversions you mentiond (E* to D*, A*, C*) are valid
> static_casts<> (assuming you defined classes B and C somewhere), and a
> C-style cast should produce a static_cast in all such cases.  Perhaps you
> could elaborate on "the memory just wasn't in the expected places" - how
do
> you know?

> The gist of vtordisp is this:  if vtordisp is on (/vd1, the default), then
> the compiler implements virutal functions the way they're specified in the
> C++ spec.  If vtordisp is off (/vd0), then virtual function calls from the
> constructor of destructor of a class with virtual bases will not work
> correctly (most likely, the program will crash).  Use /vd0 or #pragma
> vtordisp(off) only if you know absolutely that no class with virtual bases
> makes calls to virtual member functions from the constructor or
destructor.

> -cd



Sun, 17 Apr 2005 07:00:15 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. off-topic (comp.lang.c.off-topic)

2. Ways of turning echo off ... off

3. Power On/Off and Turn off screen?

4. Data On/Off Line

5. turn off debugging slop area in VC++ IDE ?

6. How to turn off file watcher

7. turning off run time checks

8. Is there a way to turn off error handling in C#

9. Trim a comma off end of string???

10. CHttpRequestParams::Render buffer size check is off by one

11. How do I turn off the TaskList

12. Turning off or tracking specific optimizations

 

 
Powered by phpBB® Forum Software