【发布时间】:2013-10-04 23:10:36
【问题描述】:
我在声明模板类型时遇到了很大的困难,如下所示。
#include <cstdlib>
#include <iostream>
using namespace std;
template <class T>
class Foo
{
typedef T Bar;
};
template <class T>
typedef typename Foo<T>::Bar Bar;
int main(int argc, char *argv[])
{
Bar bar;
Foo<int> foo;
system("PAUSE");
return EXIT_SUCCESS;
}
我得到错误
template declaration of `typedef typename Foo<T>::Bar Bar'
关于线路
template <class T>
typedef typename Foo<T>::Bar Bar;
我这样做是因为我想避免在我的代码中写入 typename Foo::Bar。
我做错了什么?
【问题讨论】:
标签: c++ templates typedef typename