小编ryb*_*ybz的帖子

依赖的非类型模板参数

考虑以下课程:

class Foo
{
  enum Flags {Bar, Baz, Bax};

  template<Flags, class = void> struct Internal;

  template<class unused> struct Internal<Bar, unused> {/* ... */};
  template<class unused> struct Internal<Baz, unused> {/* ... */};
  template<class unused> struct Internal<Bax, unused> {/* ... */};
};
Run Code Online (Sandbox Code Playgroud)

在VC++ 2010和Comeau C++上测试时,上面的类概述按预期编译和运行.但是,当Foo将其作为模板本身时,上述代码段在VC++ 2010下会中断.

例如,以下代码段:

template<class> class Foo
{
  // Same contents as the original non-templated Foo.
};
Run Code Online (Sandbox Code Playgroud)

产生以下错误类:

C2754: 'Foo<<unnamed-symbol>>::Internal<Bar,unused>' : a partial specialization cannot have a dependent non-type template parameter
C2754: 'Foo<<unnamed-symbol>>::Internal<Baz,unused>' : a …
Run Code Online (Sandbox Code Playgroud)

c++ templates visual-c++-2010

10
推荐指数
1
解决办法
1890
查看次数

标签 统计

c++ ×1

templates ×1

visual-c++-2010 ×1