考虑以下测试1代码
struct A {
private:
class face;
friend class face;
};
struct A::face {};
template <typename _CharT>
struct C : public A::face
{};
int main()
{
C<int> x;
}
这段代码格式正确吗?我在 g++ 和 comeau 下对其进行了测试。g++ 编译得很好,而 comeau 给出以下错误消息(我认为这是正确的)
"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
在这种情况下哪个编译器是正确的?Comeau 是我所知道的最符合标准的编译器之一。g++又错了吗?
(1) 这不是现实生活中的代码。