Get Items from map and add to a vector c++ -


i rote code in program

jsonnode::const_iterator iter = root.begin();     (; iter!=root.end(); ++iter)     {         const jsonnode& arraynode = *iter;         std::string type = arraynode["type"].as_string();         if(type == "node")         {             std::string id = arraynode["id"].as_string();             double lat = arraynode["lat"].as_float();             double lon = arraynode["lon"].as_float();             node node;             node.setid(id);             node.setlatitude(lat);             node.setlongitude(lon);             nodesmap.insert( std::pair<std::string, node>(id, node) );         }         else if(type == "way")         {             std::string wayid = arraynode["id"].as_string();             waynode.setid(wayid);             std::vector<node> collection;             const jsonnode& waynodes = arraynode["nodes"];             const jsonnode& nodes = waynodes.as_array();             jsonnode::const_iterator wayiter = nodes.begin();             (; wayiter!=nodes.end(); ++wayiter)             {                 const jsonnode& arraynode = *wayiter;                 std::string id = arraynode.as_string();                 if(nodesmap.find(id) != nodesmap.end())                 {                     collection.push_back(nodesmap.find(id)->second);                     nodesmap.erase(id);                   }             }             waynode.setnodescollection(collection);             std::cout<<"item id ->>>>>>>>>>>>>" << collection[2].getid() << std::endl;         }     } 

node.h

class node { private:     std::string id;     double latitude;     double longitude; public:     node();     node(const node& orig);     node(std::string id, double lat, double lon);     virtual ~node();     void setlongitude(double longitude);     double const & getlongitude() const;     void setlatitude(double latitude);     double const & getlatitude() const;     void setid(std::string id);     std::string const & getid() const; }; 

node.cpp

node::node() { } node::node(const node& orig) { } node::~node() { } node::node(std::string id, double lat, double lon){     this->id = id;     this->latitude = lat;     this->longitude = lon; } void node::setlongitude(double longitude) {     this->longitude = longitude; } double const & node::getlongitude() const {     return longitude; } void node::setlatitude(double latitude) {     this->latitude = latitude; } double const & node::getlatitude() const {     return latitude; } void node::setid(std::string id) {     this->id = id; } std::string const & node::getid() const {     return id; } 

but when try ptint id of second item std::cout<<"item id ->>>>>>>>>>>>>" << collection[2].getid() << std::endl; gets blank value. size of collection 82, correct value collection size.

i need sort out this. in advance!

node::node(const node& orig) {     this->id = orig.id;     this->latitude = orig.latitude;     this->longitude = orig.longitude; } 

modify copy constructor this.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -