I am trying to create a map which contains the objects with different arguments.
But I found that after inserting the pair, the object will be destroyed.
If I try to use the function in this object.For example:
#include <map>
#include <iostream>
class Test{
public:
Test(double value) : value_(value){}
~Test(){std::cout<< "destroyed";}
void plusone() {value_ += 1;}
private:
double value_;
};
int main(){
std::map<long, Test> map;
map.insert(std::make_pair(1, Test(1.2)));
map[1].plusone();
return 0;
}
It will show: [Error] no matching function for call to 'Class::Class()'
[Note] candidate expects 1 argument, 0 provided
How can I do this?