C++ 友元函数的简单使用。
1. *.h
include "rectangle.h"
/*
write function rectangle.h provides
*/
Rectangle::Rectangle(int len,int wd,int ht)
{
length=len;
width=wd;
height=ht;
}
int Volume(Rectangle oRectangle)
{
return oRectangle.length*oRectangle.width*oRectangle.height;
}
2.*.cpp
#include "rectangle.h"
/*
write function rectangle.h provides
*/
Rectangle::Rectangle(int len,int wd,int ht)
{
length=len;
width=wd;
height=ht;
}
int Volume(Rectangle oRectangle)
{
return oRectangle.length*oRectangle.width*oRectangle.height;
}
3.main.cpp
#include<stdlib.h>
#include<iostream>
using namespace std;
#include "rectangle.h"
int main(void)
{
Rectangle thisRectangle(6,7,9);
int volume=Volume(thisRectangle);
cout <<"Score is:_"<<volume<<endl;
system("PAUSE");
return 0;
}