#ifndef FRIENDF
#define FRIENDF
namespace friends
{
class Box
{
public:
Box(double rlength=1.0,double rwidth=1.0,double rheight=1.0);
~Box();
void Show();
//friend double BoxSurface(const Box& other1,const Box& other2);
friend double BoxSurface(const Box& other1);
private:
double length;
double width;
double height;
};
}
#endif
#include<iostream>
#include"friends.h"
using namespace std;
//using namespace friends;
friends::Box::Box(double rlength,double rwidth,double rheight):length(rlength),width(rwidth),height(rheight){}
friends::Box::~Box()
{
cout<<"析构"<<endl;
}
void friends::Box::Show()
{
cout<<"长:"<<length<<endl
<<"宽:"<<width<<endl
<<"高;"<<height<<endl;
}
#include<iostream>
#include"friends.h"
using namespace std;
using namespace friends;
int main()
{
Box aa(10.0,20.0,30.0);
aa.Show();
Box bb(40.0,50.0,60.0);
bb.Show();
cout<<"两高: "<<BoxSurface(aa)<<endl;
return 0;
}
double friends::BoxSurface(const Box& other1)
{
return
other1.height+other1.width+other1.length;
}