Reload & amp; reload incremental and subtraction operators. Differences between reload and rewriting

Source: Internet
Author: User

Reload & reload incremental and subtraction operators, differences between reload and rewriting

Class Rule {private: double m_Length; public: explicit Rule (double lg = 1.0): m_Length {lg }{} Rule & operator ++ (); const Rule operator ++ (int); Rule & operator -- (); const Rule & operator -- (int); void showRuleLength () {cout <"length: "<this-> m_Length <endl ;}}; inline Rule & Rule: operator ++ () {++ (this-> m_Length); return * this ;} inline const Rule: operator ++ (int) // returns a constant object. Changing {Rule rule {* this} is not allowed }; // use the copy constructor to create the object + + * this; // because the prefix ++ has overloaded return rule; // returns the copy of the object} inline Rule & Rule :: operator -- () {-- (this-> m_Length); return (* this);} inline const Rule & Rule: operator -- (int) {Rule rule (* this ); -- * this; return rule;} int main () {Rule a {4.0}; Rule B; B = a ++; B. showRuleLength ();}

 

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.