I am new to C++ programming, I am wondering what is "instantiated from here" error?
struct Data {
Data(int a, int b) {
x = a;
y = b;
}
int x;
int y;
};
std::map<int, Data> m;
m[1] = Data(1, 2);
I got several error messages
Thanks.
There is no default constructor for struct Data
. The map::operator[]
returns a default constructed instance of its value type, in this case struct Data
.
Either supply a default constructor:
Data() : x(0), y(0) {}
or use std::map::insert()
:
m.insert(std::pair<int, Data>(1, Data(1, 2)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With