首页 > 其他 > 详细

3.0 Basic Usage of Class

时间:2015-03-30 23:00:31      阅读:372      评论:0      收藏:0      [点我收藏+]

Well, this week I tried to use some class things.

Following are parts of my exercising codes.

  • Definig my class named Time

    技术分享

//note that cnt is a static member of this class to count the number of

//instances created.

  • Constructors & Overloading

   技术分享

//as you can see, the 2nd one is a Copy Constructor. And since both of

//two constructors have same name but different parameters , they

//are also kind of Overloading.

  • Pass by Values OR References

  技术分享

// when passing parameters, ref is needed in front of value types to pass by

// reference; while, it‘s not necessary if you pass an object (the output will be post

// later).

  • Other Member Functions of Class

  技术分享

//these functions are used to display the contents of the instances.

----------So Much About The Time class---------

Now, let me write some codes to test the Time class.

  • Creating Objects

  技术分享

//create two objects t1 and t2(with copy constructor)

  • Function Testing

  技术分享

// I first invoked GetBirthTime, passing an object, then invoked GetBirthTime

// secondly, passing value types by reference.

---------------So Much For Test---------------

In the end, let‘s have a look at our Output...

  技术分享

// pay attention to the change of the cnt (static member);

//also, we‘ll find the amazing effect of passing by reference.

-----------END  & To be CONTINUED-----------^ ^

 

3.0 Basic Usage of Class

原文:http://www.cnblogs.com/lyli/p/4379202.html

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