C++ 11 standards - initialize member variables in header
-
Is it necessary to initialize member variables with nullptr or Q_NULLPTR in header files? If yes, why is it so required, when I do proper initialize it the ctor initialization list.
in MyDialog.h,
QDialog* m_Dialog = Q_NULLPTR;
and in MyDialog.cpp...I do
MDialog()::MDialog() : QDialog() , m_Dialog(new QDialog()) { }
And in destructor, I do proper delete n setting it to nullptr.
Why is the below required?
QDialog* m_Dialog = Q_NULLPTR;
-
@sayan275 said in C++ 11 standards - initialize member variables in header:
Why is the below required?
QDialog* m_Dialog = Q_NULLPTR;It is not required :-)
-
@J.Hilk said in C++ 11 standards - initialize member variables in header:
@sayan275
its like placing your hand in front of you nose, whilst sneezing.- Its polite, and I might just prevent headache later on.
omg, best comment ever :D Very well put.
-
@sayan275 honestly, I just love the C++11 member init. it will save you so much trouble once you add another constructor.
and by doing 'find usages' I immediately see that the pointer always has a default value.
that may be no problem in your simple example, but for more complex classes it really simplifies the readability.