Can't allocate class with forward declared value in std::map member variable
问题 In test.h : #ifndef TEST_H #define TEST_H #include <map> struct Incomplete; class Test { std::map<int, Incomplete> member; public: Test(); int foo() { return 0; } }; #endif In test.cpp : #include "test.h" struct Incomplete {}; Test::Test() {} In main.cpp #include "test.h" int main() { Test test; return test.foo(); } g++ 4.7 gives me an error that struct Incomplete is forward declared when I write g++ main.cpp test.h -o main.o . However, if I change std::map<int, Incomplete> member to std::map