设为首页 加入收藏

TOP

C++中对象指针的使用
2015-07-24 05:33:50 来源: 作者: 【 】 浏览:6
Tags:对象 指针 使用

//定义结构

Box.h:

#ifndef BOX_H
#define BOX_H
struct Box{
	double length;
	double width;
	double height;
	double volume();
};
#endif

//定义volume方法
t1.cpp:

#include "box.h"
double Box::volume(){
return length*width*height;
}

test.cpp:

#include 
  
   
using std::cout;
using std::endl;
#include "box.h"
int main(){
	Box box={70.0,60.0,40.0};
	Box* pBox=&box;
	cout<
   
    volume()<
    
     height=pBox->height+5.0; pdBox->length=pBox->length-2.0; pdBox->width=pBox->width-2.0; cout<<"Volume is:"<
     
      volume()<
       
       



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ACdream 1125(ACfun-字典序) 下一篇poj 3041 Asteroids

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: