可能重复:
Forward declaration of nested types/classes in C++如何转发声明内部类?
我有一类这样的...
class Container {
public:
class Iterator {
...
};
...
};
在其他地方,我想通过引用传递一个集装箱::迭代器,但我不想包含头文件。如果我尝试转发声明该类,则会出现编译错误。
class Container::Iterator;
class Foo {
void Read(Container::Iterator& it);
};
编译上面的代码给...
test.h:3: error: ‘Iterator’ in class ‘Container’ does not name a type
test.h:5: error: variable or field ‘Foo’ declared void
test.h:5: error: incomplete type ‘Container’ used in nested name specifier
test.h:5: error: ‘it’ was not declared in this scope
我怎样才能向前声明这个类,所以我不必包括声明迭代器类的头文件?
通用基类是我最终使用最多的解决方案。 – Coyote 2013-10-03 12:49:27
如果需要,您可以使用朋友来解决此问题。 – 2016-06-14 16:32:46