I am facing an issue in c++ STL container map.
class c1 {
map<int , vector<entity>> mapobject //where entity is a structure
c1{
entity er;
er.entityId = 1;
er.nameId = 1;
std::vector<entity> record;
record.push_back(er);
mapobject.insert(std::pair<int,std::vector<entity>>(1,record));
}
}
The problem which i am facing from the above code is , outside the constructor , all the strcuture fields contains garbage values. Will the class level variable – map not deep copy the contents ?
Please help me in this
–kumar
You need to implement a copy-constructor for
entity:C++ does not deep-copy objects by default. There are also some syntax errors in your code: