← Constructors

Fix: const Member Initialization

hard

Trade::id is const – and this constructor tries to set it with an ordinary assignment in the body, exactly the pattern the lesson warned doesn’t work for const (or reference) members. Submit as-is and read both errors before fixing anything.

The fix isn’t complicated once you see it: move id’s initialization out of the body entirely and into the member initializer list, : id(tradeId), which is the only place a const member can legally be given its value. Once set there, id remains 42 (or whatever value it starts with) for the rest of that Trade object’s life – which is exactly the point of marking a field like an ID const in the first place.

Your solution

"Run" uses the sample stdin ("42"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution