I am writing C++ for quite some time but not shy to confess this syntax caught me off guard!
struct Inner
{
int data;
};
template<class T>
struct Outer
{
T field;
template <class U>
void set(U(T::* ptr), const U* value)
{
field.*ptr = *value;
}
};
int main()
{
Outer<Inner> t;
int* value = new int(3);
t.set(&Inner::data, value);
}
What does the line field.*ptr = *value; mean?
If ptr is a pointer, shouldn't the syntax be *(field.ptr)?
Was this a long week or I am really missing something?
The code snipped is copied from here (with tiny simplifications)