#include "Car.hpp" void f() { Car a; <-- 1 Car b(100, 73); <-- 2 // ... } int main() { f(); }
When control flows over line 1, a local Car object is created and initialized by the class's default constructor. The default constructor is the constructor that can be called with no parameters (see FAQ 20.08). When control flows over line 2, another local Car object is created and initialized, this time by passing two int parameters to a constructor of class Car. The parameters (100, 73) are presumably used to set up the object (e.g., initial values for various state variables). Line 1 and line 2 probably call different constructors (but see FAQ 2.04 on default parameters). Note that in the following example b is not a Car object. Instead b is a function that returns a Car by value. void g() { Car a; <-- 1 Car b(); <-- 2 }
|