3.0 Basic Usage of Class

Source: Internet
Author: User

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

Following is parts of my exercising codes.

    • Definig my class named Time

    

Note that CNT was a static member of this class to count the number of

Instances created.

    • Constructors & Overloading

   

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

The constructors has same name but different parameters, they

is also kind of overloading.

    • Pass by Values OR References

  

When passing parameters, ref was needed in front of value types-pass by

Reference While, it's not necessary if your pass an object (the output would be post

Later).

    • Other Member Functions of Class

  

These functions is 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 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 has 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.