2004-11-15 11:00 PM
Summary C , inheritance, including the use of virtual functions is important. It can even be said that they are a miniature of C programming. Personally think that these theories are worth reviewing. At any time & any place.
First, it is inheritance. This concept is very good to reflect the concept of object-oriented programming. A new type inherits the properties and behaviors of existing types, and to make the new type they need. The true charm of inheritance is the characteristics of the characteristics that can be added to the base class and replace and improve the feature from the base class.
Let's talk about the theory, C provides three kinds of inheritance methods, with charts to explain that should be simple.
Class member variable
Access specifier inheritance type
Public inheritance Protected inheritance Private Inheritment PUBLIC is directly from any non-Static member function, friend function, and non-member function to PROTECTED in the derived class.
Can be directly used by any non-Static member function, friend function is visited in the derived class for Private
Can be directly accessed by any non-Static member function and a friend function in the derived class for protected, which can be directly accessed by any non-Static member function and a friend function to the derived class for protected to protected to protected directly from any non-Static member functions and friends. Function Access In Derived Class For Private, you can directly access the private group in the derived class in the derived class. You can access the non-Static member function and the friend function to the derived class by the non-Static member function and the friend function by the base class. Hide hidden in the base class PUBLIC or PROTECTED member function is hidden by non-Static member functions and friend function access in derived classes You can pass the base class PUBLIC or Protected member function by non-Static member functions and friend function.
According to the content inside above, we can make a corresponding combination according to your own needs.
In the public inheritance, a derived object can be processed as its base class object. In addition, it is also possible to convert a pointer of a base class object to a derived pointer, but must first ensure that it must be directed to Part of a bobbin object; if you explicitly convert the pointer to the base class object, it will be a logic error that is derived from the derived class that does not exist in the object.
Since the derived class inherits the basis of the base class, when establishing an instance object of the derived class, the constructor of the base class must be called to initialize the base class member of the partial object. The constructor of the derived class can be implicitly invocated to the base class constructor, or the constructor of the derived class is explicitly explicitly invocated by the base class. Detecting the class does not inherit the constructor and assignment operator of the base class, but the derived class constructor and assignment operator can invoke the constructor and assignment operator of the base class. The constructor of the derived class always adjusts its base class constructor to initialize the base class member in the derived class. If the derived constructor is omitted, the default constructor of the base class is called by the default constructor of the derived class. The call sequence of the designer function and the call order of the constructor is the opposite, so the secting function of the school class is called before the analytical function of the base class.
In the public inheritance, because the derived class object is also a base object, the pointer to the derived class object can be implicitly converted to the pointer to the base class object. Base class pointers and derived pointers with the mixing and matching of base class objects and derived objects have the following four possible ways:
1. Use the base class pointer to the base class directly.
2, directly use the derived class pointer to the derived class.
3. Reference a derived class object with a base class pointer. Since the object of derived class is also an object of the base class, this reference method is secure, but in this way can only reference the base class member, if trying to reference only those members in the derived class, Grammatical errors.
4, use the pointer to the pointer to the base class. This reference method can cause syntax errors. The derived class pointer must be forced to convert to the base class pointer.
Multiple inheritance means a derived class to inherit a number of base classes. 2004-11-16 6:00 AM
I was going to work in yesterday, because the sudden visit of classmates, I had to be postponed.
There is an abstract type in C . It cannot be instantiated into any object, its unique use is to provide the appropriate base class for other classes, and other classes can inherit the implementation interface. Therefore, it is usually called the abstraction class as an interface. In fact, there is no interface in C , there is an object-oriented programming language in Java, but there is no relationship, essentially the same. The performance of abstract classes is to include a pure virtual function.