我正在尝试创建一个返回枚举的函数。该函数接受一个字符串。使用算法库来小写字符串,然后使用if语句来检查它的枚举时间。
枚举定义为:
enum Location {Abs, Front, Back, Trap};
我收到以下警告:
warning: variable 'enum_location' is used uninitialized whenever
'if' condition is false [-Wsometimes-uninitialized]
if(location_string == "abs")
以下是功能:
milestone::Location Task::convert_to_enum(std::string location_string)
{
std::transform(location_string.begin(), location_string.end(), location_string.begin(), ::tolower);
milestone::Location enum_location;
if(location_string == "trap")
{
enum_location = milestone::Trap;
}
else if (location_string == "back")
{
enum_location = milestone::Back;
}
else if(location_string == "front")
{
enum_location = milestone::Front;
}
else if(location_string == "abs")
{
enum_location = milestone::Abs;
}
return enum_location;
}