PDA

Click to See Complete Forum and Search --> : Inheritence


NOMADMAN
Jul 7th, 2002, 02:07 PM
I have a class Cube, and a class that inherits cube called fallingCube.
In the fallingCube.h file I have:
class fallingCube : public cube {
at the top of this header file I have #include "cube.h".
But when I compile it says:
error C2504: 'cube' : base class undefined

Anyone?

Nomad

DaoK
Jul 7th, 2002, 02:10 PM
I do not know but maybe you do not have a constructor in the class cube:



class cube
{
cube(){}
}


Something like that... but I am not very good in C++ so it's just an idea.

NOMADMAN
Jul 7th, 2002, 02:46 PM
Hmm...

I have a constructor for both cube and fallingCube.
Just to let all know, the program worked fine with just cube. Only after the recent addition of the fallingCube class did it not compile.

nomad

Zaei
Jul 7th, 2002, 04:15 PM
Your code files should look something like this:

// cube.h
#ifndef CUBE_H
#define CUBE_H

class cube
{
//..
};

#endif


//cube.cpp
#include "cube.h"

// implement


// fallingCube.h
#ifndef FALLING_CUBE_H
#define FALLING_CUBE_H

#include "cube.h"

class fallingCube : public cube
{
//..
};
#endif


//fallingCube.cpp
#include "fallingCube.h"

//implement


//main.cpp
#include "cube.h"
#include "fallingCube.h"
// the above lines dont have to be in any order, you could flip them


If youve got all of your source file layed out right, post the code up here, and I will take a look at it =).

Z.

NOMADMAN
Jul 7th, 2002, 04:30 PM
They are in order. Unfortunatly my project is VERY messy.

Look at init.cpp, that is where my declaration of fallingCube is. Then its implemented at the bottom in RenderScene()
Please save your lecture on cleaniness, I know, This was just a test to help me learn how OGL works and how to do some of the things I will need for when I REALLY start programming.

Thanks Z!

nomad

Zaei
Jul 7th, 2002, 06:38 PM
You include "fallingCube.h" in Init.h, which you ALSO include BEFORE you define "cube" in "cube.h" You need to clean up where you are including things in your project =).

Z.

NOMADMAN
Jul 7th, 2002, 09:51 PM
Z, what would I do without you?!
Why do all my "big" problems seems to have such simple answers? (I know I need to know C++ better but I learn best when people answer my questions as they arise)

Thanks Z!

Nomad

Zaei
Jul 7th, 2002, 11:57 PM
It is just a matter of code organization. I used to ber eally bad at it, and in fact, most of my older projects actually had ONE cpp file, and the rest were included headers, with implementations right in them. Not cool. Now I am in the habit of one cpp per class, etc, and it really helps with organization.

For your particular problem, the real clue was the fact that the cube base class undefined error was occuring in cube.cpp, so I just needed to find out how ANY reference to fallingCube were getting in there. From that point, I simply looked into all of the headers that were included in cube.h, to find the source of the error.

Z.