I want to write
struct Foo{
MY_MACRO
};
and have that expand into
struct Foo{
void bar(Foo&){}
};
How do I define MY_MACRO?
The only things I can come up with is the following:
#define MY_MARCO(X) void bar(X&){}
struct Foo{
MY_MACRO(Foo)
};
This comes very close but is sub ideal, as I do not want to repeat the class name.
Unfortunately the following does not compile:
struct Foo{
void bar(decltype(*this)&){}
};
This is closely related this question. The answer is that you can not (yet) write something that uses the type of the class definition you are in. You will have to write a macro that includes the start of the class definition (i.e the struct Foo) and some mechanism to facilitate the typedef.
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