• Advertisement
Sign in to follow this  

classes & inheritance problem

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

Look at the error log at the bottom of my post.
#ifndef FILE_OBJECTS
#define FILE_OBJECTS

#include <iostream>
#include <string>
#include <vector>
#include <gl/glut.h>
#include <gl/glu.h>
using namespace std;
// The namespace that contains all screen object related classes


	class coords { public:
		GLdouble x, y, z;
		GLvoid change(GLfloat _x,GLfloat _y, GLfloat _z);
		};

		class point : coords { public:

			GLvoid move(GLfloat speed, GLfloat _x,GLfloat _y, GLfloat _z); 
			friend GLvoid direction_apply(coords angle, GLfloat distance, point &_position); };

	class object { public:
		point position;
		coords direction; };

		class fixed_camera : object { public:
			point target;
			point upvector; };

			class free_camera : fixed_camera { public:
				coords direction;
				GLfloat target_distance; };

		class model : object { public:
			GLint list_index;
			GLfloat size;
			GLvoid load_model( char file[50] );
			GLvoid draw(); };

	class class_mouse { public:
		bool l,m,r;
		GLfloat x,y;
		coords world;
		GLvoid calculate_world (GLfloat depth); };
	GLvoid direction_apply(point _direction, GLfloat distance, point &_position);

#endif  /* FILE_OBJECTS */


and now this function in another file:
		GLvoid model::draw() {
		glTranslatef(position.x,position.y,position.z);
		glRotatef(direction.x,1,0,0);glRotatef(direction.y,0,1,0);glRotatef(direction.z,0,0,1);
		glScalef(size,size,size);
		glCallList(list_index); }


and this is the error log: --------------------Configuration: OpenGL_basic - Win32 Debug-------------------- Compiling... objects.cpp C:\Documents and Settings\The_CyberLord\My Documents\3D\objects.cpp(78) : error C2248: 'x' : cannot access public member declared in class 'coords' c:\documents and settings\the_cyberlord\my documents\3d\objects.h(14) : see declaration of 'x' C:\Documents and Settings\The_CyberLord\My Documents\3D\objects.cpp(78) : error C2248: 'y' : cannot access public member declared in class 'coords' c:\documents and settings\the_cyberlord\my documents\3d\objects.h(14) : see declaration of 'y' C:\Documents and Settings\The_CyberLord\My Documents\3D\objects.cpp(78) : error C2248: 'z' : cannot access public member declared in class 'coords' c:\documents and settings\the_cyberlord\my documents\3d\objects.h(14) : see declaration of 'z' Error executing cl.exe. OpenGL_basic.exe - 3 error(s), 0 warning(s) ----------- How can I solve this?

Share this post


Link to post
Share on other sites
Advertisement
classess default to private inheritance, you need to change this:

class point : coords
class fixed_camera : object
class model : object


to this:

class point : public coords
class fixed_camera : public object
class model : public object

Share this post


Link to post
Share on other sites
Well you didn't state it, but I presume position is of type point?
Well you missed out the "public" keyword in the inheritance so it wouldn't have access to the public members x, y & z

so instead of:
class point : coords
try:
class point : public coords

Oh & if you get sick of declaring each class as public from the start then just use a struct instead of a class. The only difference between the 2 is that a struct is public by default while a class is private. Many people hold the illusion that structs are old C & classes are new cpp, well they can both do exactly the same thing in cpp land. Its just their default member access that is different.

Happy Coding ;]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement