友元继承的疑问
「已注销」 2007-05-09 01:54:35 有这种说法:
a friend function is not inherited. i.e. when a base class includes a
friend function, that friend is not a friend of a derived class
于是在vc中试运行如下代码
#include <iostream>
using namespace std;
class A
{
public:
int x,y;
friend ostream& operator<<(ostream& os, A& a)
{
os<< "x="<<a.x<<";y="<<a.y<<endl;
return os;
}
};
class B :public A
{
};
int main(void)
{
B b;
cout<<b;
return 0;
}
并没有出现编译问题,那么是否违反了上面的规则呢?不知道c++的规定究竟是怎样的,上哪里可以查到呢?