我有一个C++相互依存的问题,我不明白问题出在哪里?场“价值”具有不完全类型
这里是我的头:
json.array.h
#ifndef __JSON_ARRAY__
#define __JSON_ARRAY__
#include "json.object.h"
class JSON_OBJECT;
/* JSON_ARRAY */
class JSON_ARRAY {
int size;
custom_list<JSON_OBJECT> * container;
...
};
#endif
json.object.h
#ifndef __JSON_OBJECT__
#define __JSON_OBJECT__
#include "hash.h"
#include "elem_info.h"
#include "json.type.h"
class JSON_TYPE;
class elem_info;
/* JSON_OBJECT */
class JSON_OBJECT {
custom_list<elem_info> *H;
int HMAX;
unsigned int (*hash) (std::string);
...
};
#endif
json.type.h
#ifndef __JSON_TYPE__
#define __JSON_TYPE__
#include "json.object.h"
#include "json.array.h"
class JSON_OBJECT;
class JSON_ARRAY;
class JSON_TYPE {
JSON_ARRAY * _JSON_ARRAY_;
JSON_OBJECT * _JSON_OBJECT_;
std::string _JSON_OTHER_;
std::string _JSON_TYPE_;
...
};
#endif
elem_info.h
#ifndef __ELEM_INFO__
#define __ELEM_INFO__
#include "json.type.h"
class JSON_TYPE;
class elem_info {
public:
std::string key;
JSON_TYPE value;
...
};
#endif
的main.cpp
#include <iostream>
#include <string>
#include "custom_list.h" // it inculdes cpp also
#include "json.type.h"
#include "elem_info.h"
#include "json.object.h"
#include "json.array.h"
#include "json.type.cpp"
#include "elem_info.cpp"
#include "json.object.cpp"
#include "json.array.cpp"
int main()
{
JSON_ARRAY * root = new JSON_ARRAY;
JSON_OBJECT obj;
JSON_OBJECT obj1;
JSON_OBJECT * obj2 = new JSON_OBJECT;
JSON_TYPE * type = new JSON_TYPE;
...
}
当我尝试编译我的代码,我有这样的错误:
elem_info.h:10:15: error: field ‘value’ has incomplete type JSON_TYPE value;
它看起来像它不能找到JSON_TYPE。我不知道问题在哪里。
是的,好点。谢谢。 –
除非不是因为他有循环包含。 –