You should stringify id
:
#define FIELD(id) << #id "=" << ptr->get_##id()
FIELD(field1); // << "field1" "=" << ptr->get_field1()
FIELD(field2); // << "field2" "=" << ptr->get_field2()
For FIELD(field1)
, it partly results in this expression:
"field1" "="
which is two literal strings put side-by-side. These two are then concatenated, resulting in a string equivalent to "field1="
.