I want to cast a void pointer to struct reference.
Minimum example with a struct:
#include "Interface.h"
class Foo
{
public:
Foo()
: mAddress((uint32_t*)0x0803D000)
// Okay
, mStructPtr(*static_cast<const Struct*>(mAddress))
// Error: invalid static_cast from type 'const void*' to type 'const Struct&
, mStructRef1(static_cast<const Struct&>(mAddress))
// Error: 'const void*' is not a pointer-to-object type
, mStructRef2(static_cast<const Struct&>(*mAddress))
{
}
private:
const void * const mAddress;
Struct* mStructPtr;
Struct& mStructRef1;
Struct& mStructRef2;
};
Is it meaningful/possible to use the reference (how to initialize in constructor?) or do I have to use a pointer?