Thread: Inheritance problem, help please!

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Inheritance problem, help please!

    I am having this problem with inheritance:
    I have a header file that defines my base class, called CRTBaseMesh

    It looks like this:
    PHP Code:
    #ifndef RTBASEMESH_H_DEF
    #define RTBASEMESH_H_DEF

    #include "rtMD2.h"

    class CRTBaseMesh
    {
    public:
        
    CRTBaseMesh();
        ...
       ......
    private:

    };
    #endif 
    Now this is the header file containing the class that inherits from that base cl,ass, header file:
    PHP Code:
    #ifndef RTMD2_H_DEF
    #define RTMD2_H_DEF

    #include "rModel.h" //the previous header file

    class CRTMD2 : public CRTBaseMesh
    {
        public:
        
    CRTMD2();
       ..
      ....
    private:

    };

    #endif 
    The problem is that it says that CRTBaseMesh: base class undefined.
    As you see, I include the header containing the base class, what might be the catch here?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    It could be that you have recursive includes in you header files?

    Your first file #includes "rtMD2.h". I presume this is your second file. Try removing this line.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Sounds like you haven't included the proper header file. Or they're not linking properly for some reason...
    Couldn't think of anything interesting, cool or funny - sorry.

  4. #4
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    if rtMD2.h is the second one and you include it in the baseclass header before you define the baseclass no wonder you get an error

    I mean if
    Code:
    #ifndef RTBASEMESH_H_DEF
    #define RTBASEMESH_H_DEF
    
    #include "rtMD2.h" // including a class that is derived from the
    // baseclass before the baseclass is defined?
    
    class CRTBaseMesh
    {
    public:
        CRTBaseMesh();
        ...
       ......
    private:
    
    };
    #endif
    is the baseclass and CRTMD2 is defined in "rtMD2.h", the compiler have no way of knowing the baseclass for CRTMD2 since it's "typed" before the baseclassdefinition due to the #include directive..

    does this make any sense?

    also, I know you have the #ifndef directive but still, including a headerfile in the headerfile that uses the other headerfile, that uses the other headerfile, seems lika loopingaround and an awful lot of headakes to me . It's also hard to tell which is included first and that may be the error...
    why do you include the derived class's header in the baseclass ?
    maybe I'm missing something?
    /btq
    ...viewlexx - julie lexx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance problem
    By logicwonder in forum C++ Programming
    Replies: 5
    Last Post: 10-07-2006, 10:14 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Multiple inheritance problem
    By Magos in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2006, 09:27 AM
  4. Inheritance using Stack Class Problem
    By dld333 in forum C++ Programming
    Replies: 17
    Last Post: 12-06-2005, 11:14 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM