C++ Data Structure 2

来源:互联网 发布:网易房产数据 上海 编辑:程序博客网 时间:2024/06/09 18:09

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;}



原创粉丝点击