locked
weird problem with inheritance RRS feed

  • Question

  • Hi

       I have a problem with inheritance. It gives me an error as base class undefined. It worked well before some additions to the code.

       I have done all the things that I got through the forums. Still i have a problem. Please help,  any suggestions will

    be appriciated.  Thanks in advance.

     

    Saturday, April 30, 2011 6:20 AM

Answers

  • Well, you have a space in the name 'Class B' which won't help, but I suspect that's merely your transcription typo. 

    How do you know that the classB.h file you are including is the file that defines 'ClassB'?

    One way to find out is to generate the preprocessed output file (.i) and search for 'ClassB'.  To do this,temporarily edit the Properties of the .cpp file as follows:

    In Properties/Configuration Properties/C/C++/Preprocessor, set Preprocess to a file to Yes . You may also wish to set Keep Comments to Yes as well.  Then compile the file (Ctrl-F7) and look for the filename.i file in the Project's Intermediate Directory.

    Another possibility is that there is an error in your 'ClassB' declaration which means that it is actually undefined when it comes to declaring ClassA.  Of course, I can only guess this might be happening, as your ClassB declaration shows no content.  If this is the case, it means that you are prematurely focussing on subsequent error messages.  In general, it is good practice to address the earliest compilation errors first, because they can often generate many consequential errors (the 'error cascade' phenomenon).


    Answering policy: see profile.

    • Marked as answer by Peter_Yu Tuesday, May 3, 2011 6:27 AM
    Saturday, April 30, 2011 10:12 AM

All replies

  • Show code block and error.

    Nikita Leontiev
    Saturday, April 30, 2011 6:35 AM
  • code:

    class ClassB

    {

    };

    -------------------

    #include "classB.h"

    class ClassA : public Class B

    {

       //

    };

     

    Error :

     

    error C2504: 'ClassB' : base class undefined

     


    Saturday, April 30, 2011 6:59 AM
  • Well, you have a space in the name 'Class B' which won't help, but I suspect that's merely your transcription typo. 

    How do you know that the classB.h file you are including is the file that defines 'ClassB'?

    One way to find out is to generate the preprocessed output file (.i) and search for 'ClassB'.  To do this,temporarily edit the Properties of the .cpp file as follows:

    In Properties/Configuration Properties/C/C++/Preprocessor, set Preprocess to a file to Yes . You may also wish to set Keep Comments to Yes as well.  Then compile the file (Ctrl-F7) and look for the filename.i file in the Project's Intermediate Directory.

    Another possibility is that there is an error in your 'ClassB' declaration which means that it is actually undefined when it comes to declaring ClassA.  Of course, I can only guess this might be happening, as your ClassB declaration shows no content.  If this is the case, it means that you are prematurely focussing on subsequent error messages.  In general, it is good practice to address the earliest compilation errors first, because they can often generate many consequential errors (the 'error cascade' phenomenon).


    Answering policy: see profile.

    • Marked as answer by Peter_Yu Tuesday, May 3, 2011 6:27 AM
    Saturday, April 30, 2011 10:12 AM