我有一个类,就像这样...
class Container {
public:
class Iterator {
...
};
...
};
在其他地方,我想通过引用传递Container::Iterator,但我不想包含头文件。如果我试图前向声明该类,我会得到编译错误。
在其他地方,我想通过引用传递Container::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
我如何进行前置声明这个类,以便我无需包含声明迭代器类的头文件?
class Container::(public Iterator)
或类似的方式?(我不是在谈论语言今天的设计,而是关于它理论上如何设计。) - HelloGoodbye