Цитата(taiven @ 9.11.2009, 16:56 ) | При статическом создании объекта переменная 'a' не будет инициализирована. Произойдёт ли это при динамическом создании объекта(т.е. инициализируется ли 'а' значением по-умолчанию)? |
это зависит.
Код | #include <iostream>
using namespace std;
struct test { int a; int b; };
int main() { test t1; std::cout << t1.a << " " << t1.b << std::endl; test t2 = test(); std::cout << t2.a << " " << t2.b << std::endl; }
|
Код | int main() { int a; std::cout << a << std::endl; int b = int(); std::cout << b << std::endl; }
|
Цитата | To default-initialize an object of type T means: — if T is a non-POD class type (clause 9), the default constructor for T is called (and the initialization is ill-formed if T has no accessible default constructor); — if T is an array type, each element is default-initialized; — otherwise, the object is zero-initialized
|
но это не значит что конструкторы писать не надо. |