struct A {};
typedef A B;
struct C { friend struct B; };
GCC 4.7.0 20110427 tells me error: using typedef-name 'B' after 'struct'
.
So far, this seems pretty self-explanatory; after all, my example code is trying to declare-and-friend a struct
called B, which is in fact not a struct-key
.
However, I have to write friend struct A;
if A
is in fact a complex, long-winded mess of template metahackery, this is not desirable.
Am I missing something, or can we in fact not friend
types through type aliases? If not, is there any particular reason or is it just a quirk of the language?
This question brought up the issue before, but is dated and makes assertions on the matter regarding C++0x that don't appear to be true. This question instead regards the C++0x FDIS.
You can befriend arbitrary types (for non-class types, the friend declaration will be ignored), but then you shall omit struct
:
struct A {};
typedef A B;
struct C {
friend B; // equivalent: friend struct A;
// equivalent: friend A;
friend int; // ignored
};
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