的main.cpp
int main()
{
return 0;
}
cell.h
#pragma once
class _cell {};
cell.cpp
#include "cell.h"
experiment.h
#pragma once
class _experiment
{
_cell cell;
};
experiment.cpp
#include "experiment.h"
#include "cell.h"
错误:
experiment.h(5): error C2146: syntax error : missing ';' before identifier 'cell'
experiment.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
experiment.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
这让我疯了。有帮助吗?谢谢!
答案 0 :(得分:1)
您必须#include <cell.h>
来自experiment.h
,否则在_cell
中使用时experiment.h
未定义。
答案 1 :(得分:1)
将包含从cell.cpp移动到.h
·H:
#pragma once
#include "cell.h"
class _experiment
{
_cell cell;
};
的.cpp:
#include "experiment.h"
类需要成员的定义来包含它们的实例。