Common references of objects in C ++

Source: Internet
Author: User

When the object name is directly transferred as a function parameter using the object name, a new object will be created during the function call, which is a copy of the object of the form parameter. = =====

# Include <iostream> using namespace std; class Time {public: Time (int, int, int); // constructor void Print (); // output information function void reset (Time t); // reset function private: int year; int month; int day ;}; Time: Time (int y, int m, int d) {year = y; month = m; day = d;} void Time: Print () {cout <year <"/" <month <"/" <day <endl;} void Time: reset (Time t) {t. year = 0; t. month = 0; t. day = 0 ;}int main () {Time t1 (12, 12, 12); // defines an object and initializes t1.Print (); // output t1.reset (t1) as the data member of t1; // reset t1.Print () as the data member of t1; // output return 0 as the data member of t1 ;}

 

Related Article

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.