C++ typecasting

Started by
4 comments, last by infinitycool 21 years, 10 months ago
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
"Black Holes are where God divided by zero"
Advertisement

Post us some code -
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;  
Make sure you Camera class is declared like this:

class Camera: public BaseObject {}

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.

codeka.com - Just click it.
Sorry all. After pasting the code I realized I neglected to declare the base class public. Thanks for the help!
"Black Holes are where God divided by zero"
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.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]

This topic is closed to new replies.

Advertisement