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?
It does not matter, but usually it’s better (in my humblest of opinions) to define them in the .cpp file, in order to hide the implementation from users of the class.