Consider the following test1 code
struct A {
private:
class face;
friend class face;
};
struct A::face {};
template <typename _CharT>
struct C : public A::face
{};
int main()
{
C<int> x;
}
Is this code well formed? I tested it under g++ and comeau. g++ compiles it fine whereas comeau gives the following error message (which I think is correct)
"ComeauTest.c", line 12: error: class "A::face" (declared at line 9) is inaccessible
struct C : public A::face
^
detected during instantiation of class "C<_CharT> [with _CharT=int]"
at line 17
Which compiler is correct in this case? Comeau is one of the most standard conforming compiler that I know of. Is g++ wrong again?
(1) This is not a real life code.
It's incorrect. face
is private, so it's not accessible from C. This would only be legal if C had been friended from A, not face
. face
is a private member, and so friend
ing it has no effect.
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