Jump to content
  • Advertisement
Sign in to follow this  
d h k

No Access To Public Variables?

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

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
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

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
Sign in to follow this  

  • 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!