C++ Singleton Constructor and Destructor
- by Aaron
Does it matter if the constructor/destructor implementation is provided in the header file or the source file? For example, which way is preferred and why?
Way 1:
class Singleton
{
public:
~Singleton() { }
private:
Singleton() { }
};
Way 2:
class Singleton
{
public:
~Singleton();
private:
Singleton();
};
In the source .cc file:
Singleton::Singleton()
{
}
Singleton::~Singleton()
{
}
Initially, I have the implementation in a source file, but I was asked to remove it. Does anyone know why?