Consider the following C++ code:
class A {
int x, y, z;
public:
A();
};
class B {
A a;
public:
B() {}
};
A::A() {x = 0; y = 0; z = 0;}
Class A has a constructor A::A(), used to initialize three of the class’s data members. Class B has a constructor declared inline (defined in the body of the class declaration). The constructor is empty.
Suppose that we use a lot of B class objects in a program. Each object must be constructed, but we know that the constructor function body is empty. So will there be a performance issue?
The answer is possibly “yes”, because the constructor body really is NOT empty, but contains a call to A::A() to construct the A object that is part of the B class. Direct constructor calls are not used in C++, but conceptually we could think of B’s constructor as containing this code:
B::B() {a.A::A();} // construct “a” object in B class
There’s nothing wrong about doing things; it falls directly out of the language definition. But in complex cases, such as ones involving multiple levels of inheritance, a seemingly empty constructor or destructor can in fact contain a large amount of processing.


Thanks for the article. But the construction of A object happens even in the absence of the empty constructor.