I currently have this macro
#define bind(OBJECT, ROLE) \
assert( sizeof(*ROLE) == 1 ); \
ROLE = reinterpret_cast<decltype(ROLE)>(OBJECT);
It is causing some name clashing issues so I’d like to move this into a templated function like
template<typename T1, typename T2>
void bind(T1 obj, T2 r) {
assert( sizeof(*r) == 1 );
r = reinterpret_cast<T2>(obj);
};
However, I suspect that this is not possible, but would like to be confirmed on this? In order to change r, I must have a pointer to a pointer?
You will need at least need a reference:
Another option is to use a template conversion operator. Then you can call with the syntax:
The code would be more-or-less like this: