模板类模板方法参数中的模板别名不起作用
Template alias not working in argument of template class template method
当我声明模板类的模板方法,其参数类型由模板别名指定时,我得到一个编译错误。如果我将模板类更改为类,它就会编译。如果我用实际类型(这里是Templ<bool>
)替换模板别名,它也会编译。当它是模板类且参数类型是模板别名时,为什么不起作用?
编译器为gcc版本4.8.0 (Ubuntu/Linaro 4.8.0-2ubuntu2~12.04)
template <template <typename T> class Templ>
using Bool = Templ<bool>;
template <typename T>
class Foo {
private:
public:
template<template<typename U> class Templ>
void method(Bool<Templ> boolTempl);
};
template <typename T>
template <template <typename U> class Templ>
void Foo<T>::method(Bool<Templ> boolTempl) {
}
int main() {
Foo<char> foo;
return 0;
}
g++ templTest12.C -o templTest12 -std=c++11
templTest12.C: In substitution of `template<template<class T> class Templ> using Bool = Templ<bool> [with Templ = Templ]':
templTest12.C:17:6: required from `class Foo<char>'
templTest12.C:30:12: required from here
templTest12.C:2:25: error: `template<class U> class Templ' is not a template
using Bool = Templ<bool>;
这似乎是gcc 4.8.0中的回归,因为gcc 4.7.2编译两个版本都没有错误。标准14.1/2明确规定
类和typename之间没有语义上的区别模板参数。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- 模板类模板方法参数中的模板别名不起作用
- 当基类具有两个或多个模板参数时,C++11 别名基模板类变量在模板派生类中不起作用
- 模板别名不起作用