I have a method which goes through a vector of type
StateItem
for(int i = 0; i < stateItems.size(); i++)
StateItem &st = stateItems[i];
switch (st.state)
case Effect:
result += std::string(", \"effect\": ") + st.value.value;
break;
case Hue:
result += std::string(", \"hue\": ") + st.value.intValue.str();
break;
case On:
result += std::string(", \"on\": ") + std::string(st.value.value);
break;
default:
break;
In the case Hue
I get the following Compiler error:
Member reference base type 'int' is not a structure or union
I can´t understand the problem here.
Can anyone of you please help me?
You're trying to call a member function on intValue
, which has type int
. int
isn't a class type, so has no member functions.
In C++11 or later, there's a handy std::to_string
function to convert int
and other built-in types to std::string
:
result += ", \"hue\": " + std::to_string(st.value.intValue);
Historically, you'd have to mess around with string streams:
std::stringstream ss;
ss << st.value.intValue;
result += ", \"hue\": " + ss.str();