C + +-class

Source: Internet
Author: User

Class A;

Class Members:

1. Function members

Constructor: A special member function that cannot be declared as a const

The constant pointer this:this type is "a *const" and always points to the "this" object that invokes the member function;

Const member function: Used to modify the type of the implicit this pointer, modified after the this pointer type is "const A *const". Equivalent to the this pointer added " Bottom const", can cause overloading;

The function that returns the This object:

/* Note the return type and the return statement */  & Sales_data::combine (const Sales_data &RHS)    {... return *this;     // Dereference this pointer    }

Const can cause overloading

Not finished ...

2. Data members

Typically encapsulated as in the "private" part, the private part encapsulates (that is, hides) the implementation details of the class.

Variable data member (mutable keyword ): For variable data members, any member function, including the const function, can change its value within.

class screen{public:    voidconst;   // Const member Functions Private :    mutable size_t access;           // Variable data members }voidconst{    ++access;                  // Change Access}

initial value in class : When we provide an initial value in a class, we must use "=" or curly braces.

3. Type Members

class screen{public:    typedef std::string:: Size_type pos;  // type member pos Private :    pos cursor=0;    pos Height=0;    std::string contents;

A class can customize an alias for a type in a class, and the type alias defined by the class has access restrictions (public or private) like other members;

The members used to define the type must first be defined and used, usually where the class begins !

4. Friends

A friend declaration is placed in the same header file as the class itself;

In order for a friend to be visible to the user of the class, the function is specifically declared once outside the class (in addition to the friend declaration inside the class);

Private members of the class can be accessed, and private data members of the class can be overwritten. Abusing a friend destroys the encapsulation of a class.

C + +-class

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.