I read a comment from from GMan , which
class A
{
public:
A() :
m_ptr() // m_ptr is implicitly initialized to NULL
{ }
};
should be preferred
class A
{
public:
A() :
m_ptr(NULL) // m_ptr is explicitly initialized to NULL
{ }
};
Note the absence NULLin the first example.
Is GMan right? This may be subjective, so "Do you prefer empty initializers for default initialization?" may be more appropriate.
Also, if you prefer empty initializers, is this applicable to other integral elements?
class B
{
public:
B() :
m_count(),
m_elapsed_secs()
{}
private:
std::size_t m_count;
float m_elapsed_secs;
};
Of course, please defend your point of view with a description of why you should be preferred over others.
source
share