Initialized by default or initialized value

From this answer , in C ++ 03, the POD type gets initialized by default, if ()omitted, otherwise the value is initialized.

// POD type
struct foo {
     int x;
};

// value-initialized
new foo();

But if a custom constructor is provided, will any of the following objects be considered a standard or initialized value?

// non-POD type
struct bar {
     bar(int x = 0):x(x) {}
     int x;
};

new bar();
new bar(42);
+5
source share
2 answers

In C ++ 03, the POD type gets initialized by default if () is omitted, otherwise the value is initialized.

, . ++ 03, 8.5/9, POD , - " ". , . - , POD, , (8.5/5), (.. - 8,5/7). , / POD- . POD- , .

-POD-, , , (). :

bar* ptr_a = new bar; //default initialization
bar* ptr_b = new bar(); //value initialization

, -POD , , , 8.5/5, . , , bar, , .

+3

, . , :

struct UDT
{
  int a;
  int b;
  Foo c;
  Foo d;
  UDT() : a(), c() {}
};

UDT UDT::a UDT::c ( a ), , UDT::b UDT::d ( b , d ).

. 8.5 . 12.6.2 ( 8).

+2

All Articles