composition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

composition

I'm learning about composition and I noticed that if you do not use contructor initializer list to assign values to the object, it does not work... why is this? (without initializer list) https://code.sololearn.com/cYXmzgII3ext/?ref=app (with initializer list) https://code.sololearn.com/cI388PPbezFQ/?ref=app

1st Jan 2022, 3:27 PM
Sheldon 10110
Sheldon 10110 - avatar
1 Answer
+ 3
It is because in C++ if you only define a constructor with parameters you must always intilialize it with paremeters. You have to overload the constructor to the eye class and add one that takes no parameters for it to work.
1st Jan 2022, 5:11 PM
aklex
aklex - avatar