首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++的模版有关问题

2012-09-14 
求助C++的模版问题templateclass Tclass Test{private:Txpublic:class CrefTest(T r) { x r }Cref

求助C++的模版问题
template<class T>
class Test
{
  private:
  T x;

  public:
  class Cref;

  Test(T r) { x = r; };
   
  Cref te() ;
};

template<class T>
class Test<T>::Cref
{
  private:
  T t;

  public:
  Cref(T x)
  {
  t = x;
  }
};

template<class T>
Test<T>::Cref te()
{
  return Test<T>::Cref(x);
}

int main(int argc, char *argv[])
{
  return 0;
}

这段代码无法编译通过,
在G++下编译后的错误消息提示为:

hello.cpp:错误:‘Test<T>::Cref’之前需要‘typename’,因为‘Test<T>’是一个有依赖的作用域
hello.cpp:错误:expected unqualified-id before ‘int’


[解决办法]
template<class T>
typename Test<T>::Cref te()
提示已经很清楚了
具体自己google 模板参数依赖

热点排行