【发布时间】:2018-02-04 13:13:22
【问题描述】:
我有一个简单且可重现的代码,如下所示:
template <typename T>
class Proxy {
private:
Wrap<T> &self; // If I comment this, it will work
public:
Proxy() {}
};
template <typename T>
class Wrap {
T *p;
public:
Proxy<T> foo() {
return Proxy<T>();
}
};
int main()
{
return 0;
}
我得到的错误是:
'Wrap' 没有命名类型
如果我评论Wrap<T> &self,那么它会起作用,但这不是我需要的。我需要Wrap<T> 成为Proxy 班级的成员。我怎样才能做到这一点?
【问题讨论】:
-
在
Proxy之前声明。 -
然后我得到
Proxy does not name a type。 -
声明与定义不同。
-
谢谢你,马里奥!我明白了!
标签: c++ templates declaration forward-declaration