G ++ error: specialization after instantiation (template class as friend)

Consider the following C ++ code:

template <class T> class Singleton {}; class ConcreteSingleton : public Singleton<ConcreteSingleton> { template <class T> friend class Singleton; }; int main() {} 

Singleton should be a friend of ConcreteSingleton :

It works with Microsoft Visual C ++ compiler. But I can not compile it with g ++ 4.8.4. Error:

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

Is there any way to fix this?

+5
source share
1 answer

This is GCC # 52625 error .

Workaround stolen from his comments:

  template <class T> friend class ::Singleton; // β–²β–² 

I checked that your code is not working , and this code .

+3
source

Source: https://habr.com/ru/post/1232436/


All Articles