Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Private inherit...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 43054 of 48020
Post > Topic >>

Private inheritance interferes with dynamic cast

by Marc <nospam@[EMAIL PROTECTED] > Feb 2, 2008 at 01:10 PM

Hi all. Suppose we got something like this:

class A
{
    //some code
};

class B: public SomeOtherClass, private A
{
    //some more code
};

void foo (B* b)
{
   A* a = dynamic_cast<A*> (b);
   //a is NULL!?
}

When I use this code, dynamic_cast returns NULL. However, if I change B to
be a public inheritance from A, then it works fine. So, it seems like the
kind of inheritance is affecting dynamic_cast in some way. My question is:
is this correct according the C++ standard, or is it a bug in my compiler?
I'm using a pre-release version of g++ 3.3 (I know I shouldn't be using
it,
but it's a long, non-related story).

-- 
Marc
 




 4 Posts in Topic:
Private inheritance interferes with dynamic cast
Marc <nospam@[EMAIL PR  2008-02-02 13:10:48 
Re: Private inheritance interferes with dynamic cast
"Bo Persson" &l  2008-02-02 16:01:06 
Re: Private inheritance interferes with dynamic cast
tragomaskhalos <dave.d  2008-02-02 10:22:45 
Re: Private inheritance interferes with dynamic cast
Andrey Tarasevich <and  2008-02-02 10:45:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 9:03:03 CDT 2008.