composition | Sololearn: Learn to code for FREE!

+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

c++

1/1/2022 3:27:41 PM

Sheldon 10110

1 Answer

New 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.