Results 1 to 8 of 8

Thread: Inheritence

  1. #1
    NOMADMAN
    Guest

    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

  2. #2
    DaoK
    Guest
    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.

  3. #3
    NOMADMAN
    Guest
    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

  4. #4
    Zaei
    Guest
    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.

  5. #5
    NOMADMAN
    Guest
    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

  6. #6
    Zaei
    Guest
    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.

  7. #7
    NOMADMAN
    Guest
    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

  8. #8
    Zaei
    Guest
    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
  •  



Click Here to Expand Forum to Full Width