Given a Plain Old Data struct
struct Point
{
int x;
int y;
};
I can do
Point * p1 = new Point; // members x, y uninitialised
Point * p2 = new Point(); // member x, y are 0
Now suppose I have
class PointAdv
{
std::string sPrefix;
int x;
int y;
std::string sPostfix;
};
and I do
Point * p1Adv = new PointAdv;
Point * p2Adv = new PointAdv();
Can I guarantee for the class in the 2nd expression, x and y are both 0 under any ISO C++ standard? Thanks
Also do any similar guarantees for PODs and classes hold for new[] (array new)?
Other StackOverflow questions are similar to this, but they do not make it clear what happens when the class is a mixture of class types and built-in types. I wish to know whether the builtin-types get zero initialised despite the presence of members that are class types when using new type();