I don't really know how to describe this problem but I have a template class that stores an array of value and casts it out to various data types. Generally I'm not going to cast a boolean to a float but it has to be implemented because of the way the templates work.
This causes a weird issue where when T[] = bool[] I get an error on this code:
virtual bool getBool(uint i) {
bool b;
b = *reinterpret_cast<bool*>(&values[i]);
return b;
}
Compliler error:
error: taking address of temporary
But this compiles and works fine:
virtual bool getBool(uint i) {
bool b;
T c = values[i];
b = *reinterpret_cast<bool*>(&c);
return b;
}
These two pieces of code work exactly the same but the first will not compile when T is bool. int, float, and std::string work as intended with both versions of this code. (gcc c++11)
Why does this happen?