P
Peter Jansson
Hello,
I have the following code:
std::map<int,std::set<std::string> > k;
k[0]="1234567890";
k[1]="2345678901";
//...
std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)
throw(std::runtime_error)
{
std::map<int,std::set<std::string> >::const_iterator i;
i=k.find(0);
if(i==k.end())
throw std::runtime_error("No zero in k.");
return i->second;
}
Compilation of this code goes well, but I have the following problem while
executing this in my implementation: "Segmentation fault". I have
pin-pointed the problem to be the last return statement. When I ignore
using find(int) and instead loops over the map with the following code,
everyting goes fine.
std::set<std::string> strings;
for(i=k.begin();i!=k.end();i++)
{
if(k->first==0)
strings=k->second;
}
return strings;
Anybody know what is going on here?
Regards,
Peter Jansson
http://www.jansson.net/
I have the following code:
std::map<int,std::set<std::string> > k;
k[0]="1234567890";
k[1]="2345678901";
//...
std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)
throw(std::runtime_error)
{
std::map<int,std::set<std::string> >::const_iterator i;
i=k.find(0);
if(i==k.end())
throw std::runtime_error("No zero in k.");
return i->second;
}
Compilation of this code goes well, but I have the following problem while
executing this in my implementation: "Segmentation fault". I have
pin-pointed the problem to be the last return statement. When I ignore
using find(int) and instead loops over the map with the following code,
everyting goes fine.
std::set<std::string> strings;
for(i=k.begin();i!=k.end();i++)
{
if(k->first==0)
strings=k->second;
}
return strings;
Anybody know what is going on here?
Regards,
Peter Jansson
http://www.jansson.net/