Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C++ For Dummies (2004) [eng].pdf
Скачиваний:
84
Добавлен:
16.08.2013
Размер:
8.09 Mб
Скачать

Chapter 17: Making Constructive Arguments 237

class Student

{

public:

Student (int id, int age) : sAge(age), sId(id){} const int sId;

const int sAge;

};

In this example, sId is constructed before sAge, even though sId appears second in the constructor’s initialization list. The only time you might detect a difference in the construction order is when both data members are an instance of a class that has a constructor that has some mutual side effect.

Destructors destruct in the reverse order of the constructors

Finally, no matter in what order the constructors kick off, you can be assured that the destructors are invoked in the reverse order. (It’s nice to know that at least one rule in C++ has no ifs, ands, or buts.)

238 Part III: Introduction to Classes