Archived

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

C++ typecasting

This topic is 5648 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

Hi has anyone seen this error before? error C2243: ''type cast'' : conversion from ''class Camera *'' to ''class BaseObject *'' exists, but is inaccessible I''m not sure what the inaccessible part means. Camera is derived from BaseObject so this should work... Thanks for any help beforehand, Infinitycool

Share this post


Link to post
Share on other sites
How have you inherited? If you have private or protected inheritance then you will get this error when you cast back to the base class. ie...


  
class BaseObject {};
class Camera : private BaseObject {};

Camera m_Camera;
BaseObject *m_BaseObject = &m_Camera;

Share this post


Link to post
Share on other sites
quote:
Original post by Dean Harding
If you don''t have the public it defaults to private (or is it protected? I don''t remember...) and you''ll get this error.


You are correct. Everything about classes are private as default. Everything about structs are public as default.

Share this post


Link to post
Share on other sites