Question Details

No question body available.

Tags

c++ constructor member-initialization

Answers (1)

July 27, 2026 Score: 7 Rep: 105,946 Quality: High Completeness: 60%

1. Storage for the Account object is obtained.

The storage can be allocated whenever, it's not a concern of the constructor. Under the hood, the constructor receives a pointer to whatever existing storage the object needs to be constructed in.

I suggest reading about placement-new, which allows constructing objects in any storage (so any random unsigned char array can serve as a storage for your class).

2. The balance member already exists. [when the storage is allocated]

So this is wrong too, since you can allocate the storage yourself as early as you want, long before constructing an object in it. Naturally, the fields of that object won't exist yet.

int balance; begins existing (its "lifetime starts") when the constructor starts executing, but before its body is entered. The presence of : balance(x) doesn't affect when the lifetime of balance starts. All non-static data members have their lifetime started in the order they're declared, before the constructor body is entered.

In your first example, starting the lifetime of balance is purely abstract (compiles to no code), and yes, its value is indeterminate (or erroneous since C++26). In the second example, it compiles to the same as assigning to balance.

4. The constructor body begins executing.

5. balance = x; assigns the value x to that existing int. This is the assignment not initialization.

This part is correct.