c++ - 显式特化中不允许存储类

标签 c++ gcc

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

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

A storage-class-specifier other than thread_local shall not be specified in an explicit specialization

关于c++ - 显式特化中不允许存储类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41019149/

相关文章:

c++ - 类中的动态内存(分配内存和访问元素)

gcc - 在 GCC 复合语句表达式中调用 return

linux - IN 指令段错误,内联汇编 GCC

c++ - 如何编写结构化绑定(bind)的概念?

c++ - 编译器无法推导出模板函数的类型?

c++ - 带有 Id 的 Qt 按钮

c++ - 在模板类之外定义运算符重载

c - 如何在c中对主文件的功能进行单元测试

c++ - 为什么即使函数是内联的,这段代码也会变慢?

c++ - 实现 C++ grpc 异步客户端时如何轮询 CompletionQueue?