Thread: Base Class Undefined

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    18

    Base Class Undefined

    I am working on a project, and am getting the base class undefined error. I have one class in one header, and another class in another header. The second class inherits from the first. I made a seperate project, and it worked fine. I have been looking for quite awhile now on how to fix this, and can't find anything that works. I have tried declaring the base class(ex: Class Unit before the inheriting one, and I am positive the includes are all there. Is there something about compiler options I should know to fix this? Is there a way to set the order in which things are compiled?

    Thnaks for any help,

    Khelder

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Which compiler?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: Base Class Undefined

    Originally posted by Khelder
    I am working on a project, and am getting the base class undefined error.
    Because you are only exposing your child class to the declaration of the class instead of the definition.

    Code:
    class A;
    class B : A {};
    is not enough information for inheritance. class B needs to know what class A is. If you are including the file with A's definition, then make sure that you don't have class A's file including class B's file (or class A's file includes a file which includes class B's file). If you do and the translation unit you are currently in includes file A before it includes file B and you have inclusion guards, then when class B gets compiled it will not have access to class A's definition. Hence you get a base class undefined error.

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    18
    Ah cool. Thanks for clearing that up for me. Works now!

    Khelder

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  2. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  3. Base class initialization
    By VirtualAce in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2004, 04:52 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Replies: 1
    Last Post: 11-27-2001, 01:07 PM