No Access To Public Variables?

Started by
3 comments, last by pex22 18 years, 7 months ago
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?
Advertisement
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
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 ;)
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...
Thats probably because a class content is private by default (and a struct content is public by default).
pex.

This topic is closed to new replies.

Advertisement