|
-
Jul 7th, 2002, 02:07 PM
#1
Inheritence
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
-
Jul 7th, 2002, 02:10 PM
#2
I do not know but maybe you do not have a constructor in the class cube:
Code:
class cube
{
cube(){}
}
Something like that... but I am not very good in C++ so it's just an idea.
-
Jul 7th, 2002, 02:46 PM
#3
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
-
Jul 7th, 2002, 04:15 PM
#4
Your code files should look something like this:
Code:
// cube.h
#ifndef CUBE_H
#define CUBE_H
class cube
{
//..
};
#endif
Code:
//cube.cpp
#include "cube.h"
// implement
Code:
// fallingCube.h
#ifndef FALLING_CUBE_H
#define FALLING_CUBE_H
#include "cube.h"
class fallingCube : public cube
{
//..
};
#endif
Code:
//fallingCube.cpp
#include "fallingCube.h"
//implement
Code:
//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.
-
Jul 7th, 2002, 04:30 PM
#5
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
-
Jul 7th, 2002, 06:38 PM
#6
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.
-
Jul 7th, 2002, 09:51 PM
#7
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
-
Jul 7th, 2002, 11:57 PM
#8
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|