Examples of default and function initialization for functions and use of Boolean parameters

Source: Internet
Author: User

code example

1#include <iostream>2 using namespacestd;3 classA4 {5  Public:6     void Set(int= -,int=5);//when declaring a function, initialize the parameters7     voidCountBOOL=false);//when declaring a function, initialize the parameters8 Private:9     intW;Ten     inth; One }; A voidA::Set(intWidthintheight) - { -W =width; theh =height; - } - voidA::count (BOOLVal//out-of-class definition functions PS: Example of using Boolean parameters - { +     if(val = =true) -cout <<"When the value of Val is true:"<< w*h <<Endl; +     Else Acout <<"when the value of Val is false:"<< w*h/2<<Endl; at } - intMain () - { - A; -A.Set(); -A.count ();//using the initialized function inA.count (true);//using the Set parameters -     return 0; to}

Example results

Examples of default and function initialization for functions and use of Boolean parameters

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.