【发布时间】:2023-03-17 09:23:02
【问题描述】:
在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
在test.cpp:
#include "test.h"
struct Incomplete {};
Test::Test() {}
在main.cpp
#include "test.h"
int main() {
Test test;
return test.foo();
}
g++ 4.7 给我一个错误,当我写 g++ main.cpp test.h -o main.o 时,struct Incomplete 是前向声明的。
但是,如果我将 std::map<int, Incomplete> member 更改为 std::map<int, Incomplete*> member,main.o 将编译。为什么是这样?
【问题讨论】:
标签: c++ compiler-errors forward-declaration stdmap