zoukankan      html  css  js  c++  java
  • 3.0 Basic Usage of Class

    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-----------^ ^

  • 相关阅读:
    【Git】rebase 用法小结(转)
    修饰符访问权限。
    throws与throw关键字。
    多线程,同步代码块。
    多线程,设置线程的优先级。
    多线程,加入线程。
    多线程,守护线程。
    多线程,休眠线程。
    多线程,获取当前线程的对象。
    多线程获取名字和设置名字。
  • 原文地址:https://www.cnblogs.com/lyli/p/4379202.html
Copyright © 2011-2022 走看看