At work I\'ve been using linux and the GCC compiler for C++11 and C++14. In some of the code at work, I\'ve used a union to store both a reference and a pointer, as so: (Sim
In addition to @Brian:
You can make it compile by using e.g. std::reference_wrapper
instead of a plain reference:
#include
struct MyStruct
{
//Stuff
union { std::reference_wrapper x; double* x_ptr; };
MyStruct(double& value) : x(value) {}
//More stuff
};
int main()
{
double value = 123;
MyStruct myStruct(value);
}
live example