In-depth exploration of the C ++ Object Model

Source: Internet
Author: User

1. Class data members: static and nonstatic, class member functions: static, nonstatic, virtual, and pure-virtual. It

Their differences are:

1) static data member belongs to the class, while nonstatic data member belongs to the specific object of the class. Static data member needs to be determined by yourself

Definition, so the class already exists in the memory before it is instantiated.

Static data member is defined as: <data type> <class name >:: <static data member name >=< value>
Reference: <Class Object Name>. <static data member name> or <class name >:< static data member name>
Reference static member funtion: <class name >:< static member function name> (<parameter table>) or <Class Object Name>. <static member function name> (

<Parameter table>)

2) if a class contains the pure-virtual function, the class is an abstract class and cannot be instantiated. You can use virtual functions in the base class to implement a function.

Define your own implementation methods in the derived class to achieve polymorphism.

3) static member functions are the same as static data member functions. They all belong to static members of the class and are not object members. Therefore

You do not need to use an object name to reference a member. Static member functions can only directly access static data members because they cannot obtain the this pointer.

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.