非 class 模板已声明为 class 模板

non-class template has already been declared as a class template

我从 GitHub 克隆了一个项目,该项目针对 Linux 实施(使用 Linux 特定套接字 )以用于 windows 与 VC++.

修改了需要的部分以匹配 windows 但是编译 singleton class 我得到了我不知道的错误并且搜索类似的问题没有给我任何提示.

error C2990: 'ISingleton': non-class template has already been declared as a class template

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 class ISingleton

friend class ISingleton;

其中 ISingleton 是模板 class。

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

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

friend class ISingleton<J1939Factory>;