首页 > 编程语言 > 详细

C++学习札记(2)

时间:2015-10-19 22:28:29      阅读:164      评论:0      收藏:0      [点我收藏+]

重载构造函数

#include <iostream>

using namespace std;

class rectangle

{

public:

     rectangle(){cout<<"构造一个长方形a!\n";}                                          // 无参数的构造函数

     rectangle(int l,int v){length=l;width=w;cout<<"长方形b的面积为:“

     rectangle(int l,int v,int h){length=l,width=w;height=h;cout<<"长方形的..."}       //  将 l、v、h赋值给私有变量 length、width、height

private:

     int length;

     int width;

     int height;

}

int main()

{

   rectangle a;

   rectangle b(3,4);

   rectangle c(3,4,10);

   return 0;

}

以上说明了构造函数,以及通过公有成员 调用 私有成员的方法。

 

C++学习札记(2)

原文:http://www.cnblogs.com/ruoke9/p/4893238.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!