相关疑难解决方法(0)

别名模板专业化

别名模板(14.5.7)可以明确专门化(14.7.3)吗?

我的标准fu失败了,我找不到要测试的编译器.

文本"当模板ID引用别名模板的特化时"意味着,但是然后该示例似乎引用了其他内容,暗示没有.

NB.我在n3242工作,一个在FDIS后面,其中这一部分的标题是"别名模板".大声笑.

c++ templates c++11

30
推荐指数
4
解决办法
2万
查看次数

pre-typedef一个variadic-function-pointer参数

我有一个函数foo,它使用可变参数函数指针作为其参数.

我想在函数声明之前使用"using"来定义参数的类型.

template <typename ... vARGS>
using TFuncType = void(*)(vARGS ... V_args);

template <typename ... vARGS>
void foo(TFuncType<vARGS ...> funcptr) {}

void bar(int i) {}

int main() {
  foo(&bar); // This line fails to compile.
}
Run Code Online (Sandbox Code Playgroud)

这不编译.错误(通过使用c ++ 1z的clang)是:

/make/proj/test/variadic-funcparam-deduce2.cpp:39:5: error: no matching function for call to 'foo'
foo(&bar);
^~~
/make/proj/test/variadic-funcparam-deduce2.cpp:33:36: note: candidate template ignored: substitution failure [with vARGS = int]
template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {}
Run Code Online (Sandbox Code Playgroud)

为什么"int"替换失败了?

如果我在foo()中明确写出类型,我可以成功编译:

template <typename ... vARGS>
void foo(void(*funcptr)(vARGS …
Run Code Online (Sandbox Code Playgroud)

c++ templates function-pointers variadic c++11

15
推荐指数
1
解决办法
689
查看次数

重载运算符<<表示嵌套类模板

我有以下设置:

template< class T >
struct Foo {

  struct Bar {
    Bar ( const T &t ) : otherT_( t ) {}

    T otherT_;
  };

  Foo ( const T &t ) : myT_( t ) {}

  T myT_;
};
Run Code Online (Sandbox Code Playgroud)

现在,我想制作Foo< T >::Barstremable到std :: cout和朋友的实例.我试过这个:

template< class T >
std::ostream& operator<< ( std::ostream &os, 
                           const typename Foo< T >::Bar &bar ) {
  os << "<bar: " << bar.otherT_ << ">";
  return os;
}
Run Code Online (Sandbox Code Playgroud)

但是以下代码无法编译:

  Foo< int > foo( 5 …
Run Code Online (Sandbox Code Playgroud)

c++ templates operator-overloading friend nested-class

5
推荐指数
1
解决办法
1366
查看次数