Why [] not working on map for custom class | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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 Respuesta
+ 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