类的友元
{
public:
CBottle(double height, double diameter)
{
m_Height = height;
m_Diameter = diameter;
}
friend CCarton::CCarton(const CBottle& aBottle);
private:
double m_Height;
double m_Diameter;
//这是定义友元函数的模式
};
CCarton::CCarton(const CBottle& aBottle)
{
m_Height = aBottle.m_Height;
m_Length = 4.0 * aBottle.m_Diameter;
m_Width = 3.0 * aBottle.m_Diameter;
}
int main(array<System::String ^> ^args)
{
//这里只是实现类的友元成员,并不是类的友元类
F1 f1;
F2 f2(&f1);
cout<<"var2:"<<f2.GetVar()<<endl;
CBottle cbottle(30, 5);
CCarton carton(cbottle);
cout<<"carton:"<<carton.Volume()<<endl;
system("pause");
return 0;
}
主要是顺序的定义了,个人感觉是不是类的友元类也是这样来的呢,现在不敢确定

浙公网安备 33010602011771号