非类模板已被声明为类模板

问题描述 投票:0回答:1

我克隆了一个来自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();
/* ..... */
}
c++ templates visual-c++ friend
1个回答
2
投票

问题是你定义friendISingleton

friend class ISingleton;

其中ISingleton是模板类。

template<class T>
class ISingleton { /* ... */ };

你不能:定义它friend你必须为它指定一个模板类型;通过例子(你想要什么?)

friend class ISingleton<J1939Factory>;
© www.soinside.com 2019 - 2024. All rights reserved.