On Apr 23, 10:59*am, Stefan Naewe <nos...@please.netwrote:
Quote:
On 4/23/2008 11:37 AM, nw wrote:
>
>
>
>
>
Quote:
I figured it out. Basically use find to access the elements:
>
Quote:
#include <iostream>
#include <vector>
#include <map>
>
Quote:
using namespace std;
>
Quote:
class MyMapEncap {
* public:
>
Quote:
* map<string,vector<int mymap;
>
Quote:
* const vector<int&getvec(string id) const {
* * return (*mymap.find(id)).second;
* }
};
>
Quote:
int main() {
* MyMapEncap e;
>
Quote:
* e.getvec("RAW");
>
Crash! Boom! Bang!
>
>
>
>
You need to check the return value of mymap.find() !!
>
/S
--
Stefan Naewe * * * * * *stefan dot naewe at atlas-elektronik dot com
Don't top-post *
http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please * * *
http://www.expita.com/nomime.html- Hide quoted text -
>
- Show quoted text -
Yes and probably you should think about passing the vector as a
parameter by reference, rather than returning it from the function.
In the latter you need to worry about what to return if the string id
is not in the map.