Single and Double colons in C ++

Source: Internet
Author: User

Single and Double colons in C ++

1. colon (:) usage
 
(1) represents the definition of the intra-organization bit domain (that is, the variable occupies several bit spaces)
 
Typedef struct _ XXX {
 
Unsigned char A: 4;
 
Unsigned char C;
 
}; XXX
 
(2) The colon following the constructor acts as a segmentation function. It is a class-based method for assigning values to member variables. The initialization list is more suitable for the constant const type of member variables.
 
Struct _ XXX {
 
_ XXX (): Y (0xc0 ){}
 
};
 
(3) The colons after public: and private: indicate that all the Members defined later are public or private until the next "public:" or "Private:" appears. "Private:" is the default processing.
 
(4) the class name is followed by the colon to define the inheritance of the class.
 
Class derived class name: Inheritance Method Base Class Name
 
{
 
Member of the derived class
 
};
 
Inheritance Method: public, private, and protected. The default process is public.
 
2. Double colon (: :) usage
 
(1) "domain operator"
 
For example, a Class A is declared, and Class A declares a member function void F (), but the definition of F is not given in the class declaration, when F is defined outside the class,

Void A: F () indicates that the F () function is a member function of Class.
 
(2) It is used directly before the global function to indicate that it is a global function.

For example, in VC, you can add ::
 
(3) Reference member functions and variables, and scope member operators
 
For example, system: Math: SQRT () is equivalent to system. Math. SQRT ()

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.