Say I have
T rawData;
class A {
public:
T data; // the only data member
void process(void);
// more methods;
};
What would be the safest way to A* ptr = (A*) &rawData;
in order to use ptr->process();
and other methods?
The above approach works, but some compilers warn on strict aliasing rules being violated. Of course, it's safe to create an instance of A
, set data
and then retrieve it back after all the processing - but that's exactly what I want to avoid.