L
Lionel B
This always confuses me. In the example below I would like x to be zero-
initialised on default construction of a struct A object (there is no
other initialisation/construction code required for default
construction). Which form is most appropriate?
struct A
{
double x;
// first form
// No user-supplied default constructor
// second form
A() {}
// third form
A() : x() {}
// fourth form
A() : x(0.0) {}
};
void foo()
{
A a;
/* do stuff, assuming a.x == 0.0 */
}
Could some kind soul also point me to the relevant entry in the standard?
Thanks,
initialised on default construction of a struct A object (there is no
other initialisation/construction code required for default
construction). Which form is most appropriate?
struct A
{
double x;
// first form
// No user-supplied default constructor
// second form
A() {}
// third form
A() : x() {}
// fourth form
A() : x(0.0) {}
};
void foo()
{
A a;
/* do stuff, assuming a.x == 0.0 */
}
Could some kind soul also point me to the relevant entry in the standard?
Thanks,