Y
YellowMaple
Is it possible to have pure virtual functions defined in a template
class? I'm trying to do something like this:
template <typename T>
class Singleton
{
public:
static T& getInstance(void)
{
if(m_pInstance == NULL)
m_pInstance = new T;
return *m_pInstance;
}
protected:
Singleton() { }
Singleton(const Singleton&);
virtual ~Singleton() { }
Singleton& operator=(const Singleton&);
private:
static T* m_pInstance;
};
template <typename T>
T* Singleton<T>::m_pInstance = NULL;
template <typename T>
class Resigtry
{
public:
...
virtual std::string getType() = 0;
protected:
...
virtual T* loadResource(std::fname) = 0;
};
class FontsRegistry
: public Registry<Font>
, public Singleton<FontsRegistry>
{
public:
std::string getType() { return "FONT!!"; }
protected:
Font* loadResource(std::fname) { return new Font(); }
friend class Singleton<FontsRegistry>;
};
but upon compilation i get:
C:\mingw\include\c++\3.4.2\bits\stl_list.h:: undefined reference to
`vtable for FontRegistry'
:C:\mingw\include\c++\3.4.2\bits\stl_list.h:: undefined reference to
`vtable for FontRegistry'
:: === Build finished: 2 errors, 2 warnings ===
I want to have a bunch of classes that handle external resources (i.e.
FontsRegistry for fonts, MeshRegistry for meshes, etc.) but to avoid
having to cut/paste code a whole bunch of times, I wanted to make an
abstract class Registry, that they can derive from.
class? I'm trying to do something like this:
template <typename T>
class Singleton
{
public:
static T& getInstance(void)
{
if(m_pInstance == NULL)
m_pInstance = new T;
return *m_pInstance;
}
protected:
Singleton() { }
Singleton(const Singleton&);
virtual ~Singleton() { }
Singleton& operator=(const Singleton&);
private:
static T* m_pInstance;
};
template <typename T>
T* Singleton<T>::m_pInstance = NULL;
template <typename T>
class Resigtry
{
public:
...
virtual std::string getType() = 0;
protected:
...
virtual T* loadResource(std::fname) = 0;
};
class FontsRegistry
: public Registry<Font>
, public Singleton<FontsRegistry>
{
public:
std::string getType() { return "FONT!!"; }
protected:
Font* loadResource(std::fname) { return new Font(); }
friend class Singleton<FontsRegistry>;
};
but upon compilation i get:
C:\mingw\include\c++\3.4.2\bits\stl_list.h:: undefined reference to
`vtable for FontRegistry'
:C:\mingw\include\c++\3.4.2\bits\stl_list.h:: undefined reference to
`vtable for FontRegistry'
:: === Build finished: 2 errors, 2 warnings ===
I want to have a bunch of classes that handle external resources (i.e.
FontsRegistry for fonts, MeshRegistry for meshes, etc.) but to avoid
having to cut/paste code a whole bunch of times, I wanted to make an
abstract class Registry, that they can derive from.