C++ Error: 'variable has incomplete type 'bit_vector'' - Solution and Explanation
The error 'variable has incomplete type 'bit_vector'' in C++ indicates that the compiler doesn't know what a 'bit_vector' is. This usually happens because you're trying to use the type before it has been defined. To fix this, you need to do one of the following:
- Define the 'bit_vector' type yourself: If you're using a custom 'bit_vector' class, make sure it's defined before you attempt to use it. For example:
class bit_vector {
// ... your bit_vector class definition here ...
};
- Include the necessary header file: If 'bit_vector' is part of a standard library or external library, ensure you've included the corresponding header file. For example, if 'bit_vector' is from a library called 'my_bit_vector_lib', you'd include it like this:
#include <my_bit_vector_lib>
Explanation of the Error:
The C++ compiler needs to know the size and structure of a type before it can allocate memory for a variable of that type. When you declare a variable with an undefined type, the compiler can't determine these details, leading to the 'incomplete type' error.
Looking at your code:
The error is likely happening because 'bit_vector' is not a standard C++ type. It seems you're using a custom 'bit_vector' class. You need to ensure this class is defined before the macro invocation. Here's how you might fix it:
// ... Your 'bit_vector' class definition here ...
#define _(name, Name, TYPE) \
bit_vector m##Name; \
if(name[0]){ \
namesActive = true; \
idNumberT numNames = sourceNameBase.GetNumNames(NAME_##TYPE); \
m##Name.resize(numNames); \
if(name##Exact){ \
idNumberT id; \
if(sourceNameBase.FindExactName(NAME_##TYPE, name, &id) == OK) \
m##Name[id] = true; \
else{ \
LOGW("searchHeader: " #name " does not match exactly"); \
return false; \
} \
}else{ \
for(idNumberT i = 0; i < numNames; ++i) \
m##Name[i] = strAlphaContains \
(sourceNameBase.GetName(NAME_##TYPE, i), name); \
} \
} \
_(white, White, PLAYER); //todo fix \
_(black, Black, PLAYER); \
_(event, Event, EVENT); \
_(site, Site, SITE); \
_(round, Round, ROUND); \
#undef _
Remember to always define your custom types (like 'bit_vector') before using them in your code to avoid this error.
原文地址: https://www.cveoy.top/t/topic/fA39 著作权归作者所有。请勿转载和采集!