+ 2

Why [] not working on map for custom class

Hi Trying to create a map of int and custom class object as below: Able to insert element using insert method but not working when I use subscript operator. m[2] = obj is not working if m is declared as map<int,clsTest> What's the issue here ? https://code.sololearn.com/cjiVtbLzPZAU/?ref=app

3rd Apr 2022, 10:34 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Resposta
+ 1
[] of map need class object to be default constructible. Added default constructor and error is gone.
3rd Apr 2022, 1:18 PM
Ketan Lalcheta
Ketan Lalcheta - avatar