C++ Member Reference base type 'int' is not a structure or union
c++
Solution
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();
}
Problem
I'm running into a Problem in my C++ Code. I have a union `StateValue`: ``` union StateValue { int intValue; std::string value; }; ``` and a struct `StateItem` ``` struct StateItem { LampState state; StateValue value; }; ``` 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?