我来到了同一个问题在我们的代码库这里
Can't allocate class with forward declared value in std::map member variable
描述。不完全类型为std ::成员地图
Hoever我还发现其他情况下,我们的编译器(MSVC 2017年)能够编译这个...
用我发现,在CPP定义CON组&析构函数允许文件来编译代码摆弄左右后。
在test.h
:
#ifndef TEST_H
#define TEST_H
#include <map>
struct Incomplete;
class Test {
std::map<int, Incomplete> member;
public:
Test();
~Test();
int foo() { return 0; }
};
#endif
在test.cpp
:
#include "test.h"
struct Incomplete {};
Test::Test() {}
Test::~Test() {}
在main.cpp
:
#include "test.h"
int main()
{
Test test;
return test.foo();
}
因为当你放置'struct Incomplete {};'上面的构造器/析构函数定义时,'incomplete'就完成了。 – VTT
*在cpp *中定义了con&destructor而不是什么? – stijn
它看起来像你“发现”,如果你在接口文件中命名一个方法......甚至是一个析构函数......那么它需要在你的实现文件中定义。接口中的内联方法在实现中不需要定义。看起来像适合我的设计。 –