在明确的专业化中不允许存储类

A storage class is not allowed in an explicit specialization

本文关键字:不允许 存储 专业化      更新时间:2023-10-16

我在不属于类的标题文件中具有以下代码:

template<typename Foo> static const Compl<Foo,bar> *foobar (const FBTYPE &x);
template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
    return x.funcA();
}
template<> static const Compl<typeb,bar> *foobar<typeb>(const FBTYPE &x) {
    return x.funcB();
}

该代码可以使用较旧的GCC版本进行编译,但是在较新的版本中,我会收到此错误消息:

rsvt.h(672): error #3503: a storage class is not allowed in an explicit specialization
  template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
             ^

是否知道为什么它可以与较旧版本的GCC一起使用,而不是与新版本一起使用?另外,我该如何使用GCC 5?

原因在以下报价中,现在在C 标准中:[dcl.stc]/p1

不得在明确的专业化中指定thread_local以外的存储类别