+ 1
Why map insertion is not compiled
Can any one suggest error here ? I have provided < overloaded operator as well. https://code.sololearn.com/cdgaPEt823K1/?ref=app
1 Respuesta
+ 2
The mapped type must be default-constructible, because if the key does not exist, the corresponding newly created element must first be constructed somehow before a reference to it can be returned. After all, the operator [] overload itself has no access to the value you are trying to assign afterwards.
Since your class does not provide a default constructor, an error is triggered. See:
https://en.cppreference.com/w/cpp/container/map/operator_at