【问题标题】:Template alias not working in argument of template class template method模板别名在模板类模板方法的参数中不起作用
【发布时间】:2013-05-08 01:28:38
【问题描述】:

当我声明参数类型由模板别名指定的模板类的模板方法时,我收到编译错误。如果我将模板类更改为一个类,它会编译。如果我将模板别名替换为实际类型(此处为 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>;

【问题讨论】:

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


    【解决方案1】:

    这似乎是 gcc 4.8.0 中的回归,因为 gcc 4.7.2 确实编译了两个版本而没有错误。标准 14.1/2 明确指出

    在类和类型名之间没有语义上的区别 模板参数。

    【讨论】:

    • 我确认。我用 gcc 版本 4.7.3 进行了测试,它编译得很好。
    猜你喜欢
    • 2014-01-29
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多