我克隆了一个来自GitHub的项目,该项目是针对Linux(使用Linux特定套接字)实现的,用于在VC ++中使用Windows。
修改了所需的部分以匹配窗口,但编译singleton
类我得到错误,我不知道和搜索类似的问题没有给我任何提示。
错误C2990:'ISingleton':非类模板已被声明为类模板
Singleton.h
------------
#define SINGLETON_ACCESS friend class ISingleton;
template<class T>
class ISingleton {
protected:
ISingleton() {}
static T* mInstance;
public: virtual ~ISingleton(){}
} /* class ISingleton */
template<class T>
T* ISingleton<T>::mInstance = NULL;
和
factory.h
-----------
namespace J1939 {
class J1939Frame;
class J1939Factory : public ISingleton<J1939Factory> {
SINGLETON_ACCESS; /* <---Getting Error Here */
virtual ~J1939Factory();
private:
J1939Factory();
/* ..... */
}
问题是你定义friend
类ISingleton
friend class ISingleton;
其中ISingleton
是模板类。
template<class T>
class ISingleton { /* ... */ };
你不能:定义它friend
你必须为它指定一个模板类型;通过例子(你想要什么?)
friend class ISingleton<J1939Factory>;