Consider the following C++ code:
template <class T>
class Singleton {};
class ConcreteSingleton : public Singleton<ConcreteSingleton> {
template <class T>
friend class Singleton;
};
int main() {}
Singleton
shall be a friend of ConcreteSingleton
:
It works with Microsoft's visual C++ compiler. But, I can't compile it with g++ 4.8.4. The error is:
error: specialization of ‘Singleton<ConcreteSingleton>’ after instantiation template <class T> friend class Singleton;
Is there any way to fix it?
This is GCC bug #52625.
Workaround stolen from its comments:
template <class T>
friend class ::Singleton;
// ▲▲
I have verified that your code doesn't work, and this code does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With