itcplpl
itcplpl

Reputation: 780

segmentation fault with enum

I have the following function

template<class T> T stringTo(const std::string& s)
{
 std::istringstream iss(s);
  T x;
  iss>>x;
  return x;
};

and when I apply it as follows:

session ft = stringTo<session>("F");

where session is:

enum session {F, S, T};

I get a Segmentation fault.

can you help me figure out where my error lies...

Upvotes: 0

Views: 1772

Answers (1)

Nabheet
Nabheet

Reputation: 1314

Could the problem be that you are using 'F' instead of "F"?

It seems like your stringTo function wants a string and you are sending in a char.

Btw, I don't think your approach is valid. You probably need to setup a map that takes you from string to enum or vice versa.

Maybe, this might give you an option.

Upvotes: 1

Related Questions