C ++: Reload prefix operator and reload suffix operator (take ++ as an example)

Source: Internet
Author: User

C ++: Reload prefix operator and reload suffix operator (take ++ as an example)
C ++: Reload prefix operator and reload suffix operator (take ++ as an example)

By Serena

In C ++, how does one distinguish between the overloaded prefix operator and the overloaded suffix operator? It is not difficult to find that the overload suffix operator carries the form parameter int while the overload prefix operator does not. This parameter is only used to differentiate the two parameters and has no practical significance.

We know that a ++ and a are different, for example, c = a ++ and c = ++ a. The values of two c types are different. Because the former assigns a to variable c first and then auto-increment, while the latter assigns the result of auto-increment to variable c first.

Therefore, because of this subtle difference, the code for reloading these two operators is quite different. The modern code is as follows:

/// Main. cpp // time /// Created by apple on 16/2/21. // Copyright (c) 2016 apple. All rights reserved. // # include
  
   
Using namespace std; class Time {private: int minutes; int hours; public: Time () {minutes = 0; hours = 0;} Time (int h, int m) {minutes = m; hours = h;} void display () {cout <"H" 

All of the above are my own opinions. You are welcome to give criticism and guidance. Let's discuss it together!

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.