"Deep Exploration C + + object Model" Reading notes (1)

Source: Internet
Author: User
Tags inheritance object model

In C + +, there are two types of class data members:static and Nonstatic, and three class member Functions:static, nonstatic, and virtual. Known as the following class Point statement:

class Point ...{
public:
Point(float xval);
virtual ~Point();

float x() const;
static int PointCount();

protected:
virtual ostream& print(ostream &os) const;

float _x;
static int _point_count;
};

In the C + + object model originally designed by Stroustrup, the nonstatic data members are configured within each class object, and the static data members are stored outside all class object. The static and nonstatic function members are also placed outside all class object, and Virtual functions is supported in two steps:

(1) Each class produces a bunch of pointers to the virtual functions, placed in the table, which is called virtual table (VTBL).

(2) Each class object is added a pointer to the associated virtual table. Usually this pointer is called the VPTR.VPTR setting (setting) and reset (resetting) by each class of constructor , destructor, and copy assignment operators are automatically completed. The Type_info object associated with each class (to support the runtime type Identification,rtti) is also indicated by virtual table, usually at the first slot of the table.

Virtual Inheritance * * *

An inheritance relationship can also be specified as virtual (that is, the meaning of sharing):

class istream : virtual public ios ...{ ... };
class ostream : virtual public ios ...{ ... };
class iostream : public istream,public ostream ...{ ... };

In the case of virtual inheritance, the base class, regardless of how many times it is derived from the inheritance chain (derived), will always have one entity (called the subobject). For example, there is only one entity in Virtual iOS base class in iostream.

Type of pointer * * *

Here's a zooanimal statement:

class ZooAnimal ...{
public:
ZooAnimal();
virtual ~ZooAnimal();

// ...
virtual void rotate();

protected:
int loc;
String name;
};

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.