return a STL map<>  
Author Message
Abhishek.itb





PostPosted: Visual C++ Language, return a STL map<> Top

Hi,

struct xy

{

int x;

int y;

};

i have function to fetch x and y values.i'l update the structure variables x and y. i need to populate this structure into map as a value and with the key as string like point1, point2...

So the map contents willl be like

map["point1"] = struct1.

How can I return this map object by this function, and recieve the same in other calling function.

Please can any one help and give a sample example for this.

Thanks in advance.



Visual C++11  
 
 
Viorel.





PostPosted: Visual C++ Language, return a STL map<> Top

I hope this gives some useful suggestions:

void function1(std::map< std::string, xy > & m)

{

    xy v;

    v.x = 100;

    v.y = 200;

 

    m["point1"] = v;

    . . .

}

 

void function2()

{

    std::map< std::string, xy > myMap;

 

    // make map

    function1(myMap);

 

    . . .


}


 
 
Brian Kramer





PostPosted: Visual C++ Language, return a STL map<> Top

Viorel shows you more about using the map template, but I'm unsure if this actually answers your question. You probably don't want a function to *return* the map object after you've already made a new entry to it, and I don't see why you would want to return the map entry you've just made. Can you elaborate on exactly you're trying to accomplish
 
 
Simple Samples





PostPosted: Visual C++ Language, return a STL map<> Top

 
void function1(std::map< std::string, xy > & m)

That is probably a good answer to the question; I assume it is but I cannot speak for the person asking the question.

I just want to add that it helps to use typedefs. I am sure you know what I mean. I hope the person asking the question also understands and if they do then they have all they need.