I need help to understand the following (simplified) code snipped:
template < typename R >
struct Variable
{
typedef VariableBaseTable< R > BaseType;
typedef R BaseType::* VarType; //!
template < typename Type >
R & operator()(Type * obj) const
{
return (reinterpret_cast< ObjType >(obj))->*(_variable); //!
}
// more stuff follows
}
The two lines I need help understanding are marked with a //! in the end.
I could not understand what the R BaseType::* is defining. In particular, how the ::* syntax works.
In the second marked line, I could not understand the syntax obj->*(_var), I can see that obj is being dereferenced, but what the * is doing there right after it?
typedef R BaseType::* VarType;
is a type alias which defines VarType as a pointer-to-member-of-BaseType of type R. In the second marked line, you are accessing the field _variable via the pointer-to-member access operator ->*, see e.g. this for more details about the syntax and some examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With