How can I understand what is declared here: (this is taken from another post on this forum)
template<typename C> static char (&f(ChT<int Fallback::*, &C::x>*))[1];
Here's how I read:
template of static function f
called with (ChT<int Fallback::*, &C::x>*)
, but then I can't make sense why is there an address-of operator and why is there an array?
I'm still learning how to understand C++ declarations, so please explain this slowly and carefully.
Using some typedefs:
typedef char (&arrayref_t)[1];
This is a reference to an array of characters. The array has one element.
typedef ChT<int Fallback::*, &C::x> tmpl_t;
This is a template class, instantiated with the type "pointer to an int
member of the Fallback
class", and a member pointer to x
in class C
.
static arrayref_t f(tmpl_t*);
The function now takes a pointer to a tmpl_t
and returns an arrayref_t
.
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