g ++错误:实例化后的专门化(模板类为朋友)

时间:2015-09-28 08:54:26

标签: c++ c++11 g++ friend g++4.8

考虑以下C ++代码:

template <class T>
class Singleton {};

class ConcreteSingleton : public Singleton<ConcreteSingleton> {
    template <class T>
    friend class Singleton;
};

int main() {}

Singleton应为ConcreteSingleton朋友

它适用于Microsoft的visual C ++编译器。但是,我无法用g ++ 4.8.4编译它。错误是:

   error: specialization of ‘Singleton<ConcreteSingleton>’ after instantiation
       template <class T> friend class Singleton;

有没有办法解决它?

1 个答案:

答案 0 :(得分:3)

这是GCC bug #52625

从其评论中窃取的解决方法:

   template <class T>
   friend class ::Singleton;
//              ▲▲

我已核实your code doesn't workthis code does