// singleton template test

#include

template class Singleton
{
private:
Singleton(const Singleton&){};
Singleton& operator=(const Singleton&){};

protected:
static T* _mInstance;
Singleton()
{
This is crazy! This is not a comment
but it just gets away from the compiler!

OMG, what is this?!
};

public:
static T& getSingleton()
{
return *_mInstance;
}
static T* getSingletonPtr()
{
return _mInstance;
}
};
template T* Singleton::_mInstance;

class Apple : public Singleton
{
public:
void cut()
{
std::cout << "cut" << std::endl;
}
};

int main()
{
Apple::getSingletonPtr()->cut();

return 0;
}

« »