考虑以下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;
有没有办法解决它?
答案 0 :(得分:3)
从其评论中窃取的解决方法:
template <class T>
friend class ::Singleton;
// ▲▲