Sign in to follow this  
d h k

No Access To Public Variables?

Recommended Posts

Hello everyone, I am currently working on a small game to get more into OOP as well as to become more familiar with OpenGL. So I set up some structures and classes and already started with some implementations and everything is fine - except one error: The following code shows how parts of my "game_object"-system is set up.
struct point
{
	float	x;
	/* ... */
};

class game_object
{
	public:
		point	position;
		/* ... */
};

class game_ball : game_object
{
	public:
		
		void	set_position ( float x, float y, float z );
		/* ... */
};

class player
{
	public:
		game_ball		sphere;
		/* ... */
};
[/SOURCE]
Now whenever I try to access the "position" variable of the "game_ball sphere" variable ( like this for example [inside the player class]: glTranslatef ( sphere.position.x, sphere.position.y, sphere.position.z ); ), I keep getting an error ( "No access to public element whose declaration was handled in the class 'game_object'..." ). What is this error about and why can't I access this 'normal' and public "point position" variable?

Share this post


Link to post
Share on other sites
It's because you used private inhertiance instead of public inheritance.

This:
class game_ball : game_object

should be:
class game_ball : public game_object

Share this post


Link to post
Share on other sites
The problem is here:
class game_ball : game_object

Here you use private inheritance, what you want is this:
class game_ball : public game_object

edit:
almost in time ;)

Share this post


Link to post
Share on other sites
Thanks a lot. I knew it was something obvious.

Once again I have to say I hate my C++ book for not even letting me know about this...

Share this post


Link to post
Share on other sites
Thats probably because a class content is private by default (and a struct content is public by default).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this