The role of a colon (:) in C + +

Source: Internet
Author: User

1. Colon (:) usage

(1) Represents the definition of a bit field within a mechanism (that is, the variable occupies several bit spaces)

typedef struct _xxx{

unsigned char a:4;

unsigned char c;

} ; Xxx

(2) The colon at the back of the constructor functions as a method of assigning a value to a member variable, initializing the list, and more appropriate for the const type of the member variable.

struct _xxx{

_xxx (): Y (0xc0) {}

};

(3) Public: and private: The following colon, which indicates that all the members defined later are publicly or privately held until the next "common:" or "Private:" appears. "Private:" is handled by default.

(4) The class name followed by a colon is used to define the inheritance of the class.

Class derived class Name: Inheritance mode base class name

{

Members of derived classes

};

Inheritance mode: Public, private, and protected, default processing is public.

The role of a colon (:) in C + +

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.