PHP object-oriented programming advanced features (interface, inheritance, abstract class, destructor, clone, etc.), c abstract class destructor
This article describes the advanced features of PHP object-oriented programming. We will share this with
Main content:1. Constructors and destructors in C + + class inheritance2. Static binding and dynamic binding in C + + polymorphism3. The destructor is declared as virtual function in C + + polymorphism1. Constructors and destructors in C + + class
Class Constructor
The constructor of the python class is _ init __, which is different from other functions. First, it uses two double underscores (_ init __) to distinguish it from other function names. The format is as follows:
Def _ init _ (self,
Destructor usage:1. Each destructor (without virtual) is only responsible for clearing its own members. 2. There may be a base class pointer pointing to the case where it is indeed a member of a derived class.For the second case:Correct execution:
Learning materials• base class and derived class destructor execution orderDefining derived class destructorsNote : When you define an object, you call the constructor of the base class, and then call the constructor of the derived class, which is
For objects in the heap, we usually use new/delete to create/destroy objects. When new is called, it automatically calls the constructor of the corresponding class. Similarly, when delete is called, it automatically calls the corresponding class
Post a blog. A friend on the box thinks that class's construction and destructor delay loading. Is the construction of class that is called after the initialization of the unit. The destructor of the class that was called before the unit's inverse
Object-oriented programming is based on three basic concepts: Data abstraction, inheritance, and dynamic binding. In C + +, you use classes for data abstraction, and class derivation to inherit another class from one class: Derived classes inherit
1 in C + +, dynamic binding occurs when a virtual function is called through a reference (or pointer) of a base class, and two conditions (base class reference or pointer, virtual function) are indispensableStatic bindings for default real arguments
C ++ class related issues, constructor and destructor, copy constructor instance explanations, constructor instance explanations
The basic task of object-oriented is to describe the object and classify and summarize the object. The class type is
Base * pb; inherit C; // inherit is the Pb that inherits the base = & C; Delete Pb; the object's destructor must be called. If the base class destructor are not virtual, the destructor of the corresponding class is called according to the
1. What functions are called by default in C + +When the data member type in a class is the Trival data type (that is, the struct type of the original C language), the compiler does not create ctor, copy ctor, assign operator, dctor by default.The
1. Virtual function Cause: When you call a member function through a pointer, you can only access the member function with the same name as the base class. In a overwrite with the same name, a function with the same name is called by the object
Li Jianzhong (Nanjing University of Posts and Telecommunications (Cornyfield@263.net)
Constructor
The constructor initializes the member variables (fields) in the class. The C # class has two constructor types: instance constructor and static
C ++ Object-Oriented Programming (1)
Today I have read a little bit about Object-Oriented Programming in primer. The following is my summary.
I. Virtual Functions
1. A function defined as virtual is defined by a base class that is expected to be
Before starting, analyze the association between the new operator and operator new in C ++.
New: A common operator in C ++, such as a * A = new A or a constructor with parameters. For new, there are new and :: the former is in STD.
Operator new ():
To tell the truth C + + is used in school before, from graduation to now has been using C embedded programming, now moved out of C + + grammar, if the understanding of the wrong place, but also passing friends more correct ~ ~ ~
constructor is used
This is because the basic class pointer is used to destroy the behavior of the derived class object. If the base class does not have a virtual destructor, a problem occurs. We know that there is no problem in deleting the pointer object. The
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.