Jump to content
  • Advertisement

Archived

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

Gurami

C++ Inheritence / Type Casting error

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I've run up to an error in MSVC++ that i've never seen before. I've got two classes, LinkedList and PlanetList, PlanetList is a child class of LinkedList, and when I attempt to assign the address of a PlanetList to a *LinkedList, i get the following error: error C2243: 'type cast' : conversion from 'class PlanetList *' to 'class LinkedList *' exists, but is inaccessible. The pertinent code is replicated below:
  
LinkedList *OnScreenList;
Object *LastClicked;
.
.
.
class LinkedList
    {
    //...LinkedList Body...

    }
.
.
.
class PlanetList : LinkedList
    {
    //...PlanetList Body...

    }
.
.
.
OnScreenList = ((StarObject*)LastClicked)->star.planets;
   
Now, i believe the explicit conversion from Object to StarObject works, because it works elsewhere in the code. Star.planets is a *PlanetList. Help! Thanks! Mike Edited by - Gurami on January 31, 2002 1:44:09 AM

Share this post


Link to post
Share on other sites
Advertisement
Maybe the inherited parent should be inherited public ?

class PlanetList : public LinkedList

Reg''ds,
sTeVe

Share this post


Link to post
Share on other sites
Why do you want to cast a derived class to the base class? That''s an undefined operation (because the derived class can - and most probably does - contain data/methods not present in the base class).

Anyway, try manually casting it (rather than implictly):
OnScreenList = (LinkedList *)((StarObject*)LastClicked)->star.planets; 

I expect it to fail, though.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!