C++ Member Reference base type 'int' is not a structure or union
Your intvalue is no object. It has no member functions. You could use sprintf() or itoa() to convert it to a string.
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();
}
Member reference base type 'int' is not a structure or union
int
is a primitive type, it has no methods nor properties.
You are invoking str()
on a member variable of type int
and that's what the compiler is complaining about.
Integers cannot be implicitly converted to string, but you can used std::to_string()
in C++11, lexical_cast
from boost
, or the old-slow approach of the stringstream
.
std::string to_string(int i) {
std::stringstream ss;
ss << i;
return ss.str();
}
or
template <
typename T
> std::string to_string_T(T val, const char *fmt ) {
char buff[20]; // enough for int and int64
int len = snprintf(buff, sizeof(buff), fmt, val);
return std::string(buff, len);
}
static inline std::string to_string(int val) {
return to_string_T(val, "%d");
}
And change the line to:
result += std::string(", \"hue\": ") + to_string(st.value.intValue);