c++ - 模板别名在模板类模板方法的参数中不起作用

标签 c++ templates gcc c++11 template-aliases

当我声明参数类型由模板别名指定的模板类的模板方法时,我收到编译错误。如果我将模板类更改为一个类,它会编译。如果我将模板别名替换为实际类型(此处为 Templ),它也会编译。为什么它不起作用,当它是模板类并且参数类型是模板别名时?

编译器为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 明确指出

There is no semantic difference between class and typename in a template-parameter.

关于c++ - 模板别名在模板类模板方法的参数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16431216/

相关文章:

java - 此代码出现运行时错误与编译错误的原因

c++ - -Wformat-truncation错误将2-3个字节写入2-6个字节的区域

c++ - 有人使用 constream (constrea.h) 库吗?

c++ - 如何使用编码的 AAC 数据手动创建 AVPacket 以发送 mpegts?

xml - 匹配 xslt 的子字符串模板

c - 通过 MacPorts 安装 gcc45 后,如何使用它在我的 Mac 上构建 C 语言?

被调用的库过程在 gnu/linux 上无限循环运行

c++ - 在具有统一初始化语法的 C++11 move 构造函数中使用 std::move

c++ - BitmapEx.h 的问题

c++ - 类模板的静态方法的奇怪问题