简体   繁体   中英

C++ header file inclusion error

I have a header "myHeaderFile.h" file looks as below which is used by both release exe and unit test exe.

#ifndef MYHEADERFILE_H
#define MYHEADERFILE_H

namespace myname1
{
namespace myname2
{
    class A
    { 
           ...
    };
#ifdef MYTESTCLASS
    class TestABase
    {
        ...
    }
#endif
}
}
#endif

Now we have for unittest file myUnitTest.h file file as below

#ifndef MYUNITEST_H
#define MYUNITTEST_H

#ifndef MYTESTCLASS
#define MYTESTCLASS  1
#endif 
#include "myHeaderFile.h"
class TestClass : public myname1::myname2::TestABase
{
  ...
};
#endif

now in myUnitTest.cpp i have following

#include "myUnitTest.h"

// Definition stuff.

When i compile i am getting error as error C2039: TestABase: is not a member of myname1::myname2' myUnitTest.h(31): error C2504: TestABase: base class undefined

what is causing above error? Please help me in resolving above error. Note: myHeaderFile.h comes from library so i cannot change this header file.

Thanks!

You need to include myHeaderFile.h in myUnitTest.h . Do that after the block:

#ifndef MYTESTCLASS
#define MYTESTCLASS  1
#endif

Edit

As this did not help then there may be a problem with the MYTESTCLASS definition. Do you include myHeaderFile.h anywhere else? Maybe you can try to define the MYTESTCLASS in compiler options instead of in the myUnitTest.h header file. Maybe you can just remove the #ifdef MYTESTCLASS check to see if that is the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM