Pointers are "POD types"...a.k.a. "Plain Old Data". The rules for when and where they are default-initialized are summarized here:
Default initialization of POD types in C++
So no. It doesn't matter what your constructor for a class is, if it's a raw pointer as a member of the class. You aren't actually instantiating the class. So members like Foo *
or std::vector<Foo> *
or anything ending in * will not be initialized to nullptr.
The smart pointer classes are not POD. So if you use a unique_ptr<Foo>
or a shared_ptr<Foo>
that is creating instances of classes, that do have a constructor that makes them effectively null if you do not initialize them.
Does it matter if I do MyCLass* o = new MyCLass; or I do MyCLass* o = new MyCLass(); in C++11?
One question per question, please.
Do the parentheses after the type name make a difference with new?