Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile project: error in locale.h file

I'm trying to compile a project that has the following header:locale.h;

locale.h:

class LOG4CXX_EXPORT Locale
{
public:
       ...

protected:
    Locale(const Locale&);
    Locale& operator=(const Locale&);
    const LogString language; <-- error
    const LogString country;  <-- error
    const LogString variant;  <-- error
}; // class Locale

Could anyone give me some suggestions ?

I'm getting this error. I am not sure what is the problem.

/LOGGER/include/log4cxx/helpers/locale.h:42:41: error: field ‘language’ has incomplete type
                     const LogString language;
                                     ^
/LOGGER/include/log4cxx/helpers/locale.h:43:41: error: field ‘country’ has incomplete type
                     const LogString country;
                                     ^
/LOGGER/include/log4cxx/helpers/locale.h:44:41: error: field ‘variant’ has incomplete type
like image 348
cristian Avatar asked Sep 04 '15 08:09

cristian


1 Answers

Consider the following code:

class MyClass;

int method1(const MyClass& param);
MyClass& method2();
const MyClass instance; // <- error here

The declaration of MyClass is a forward declaration. All the compiler know is that the class exists (it doesn't know its members, size...), that's why it is called an incomplete type. You can use references or pointers of that class, but that's it. See more info here When can I use a forward declaration?

So it seems that in your code, you only have a forward declaration of LogString type, and not a full declaration. Check your include files and include order so you get the full declaration of this class.

like image 137
Dazzibao Avatar answered Nov 12 '22 20:11

Dazzibao