Today's one-day course, so the study of ruminations on C ++ can only take 30 minutes at noon,
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------
Proxy type:
1> import conditions.
Class polymorphism is so practical in programming. We can use a pure virtual parent class pointer to operate on all its subclass objects, this makes programming easy and convenient.
We can easily use some template containers or custom data structures to manage a category of things (for example, we can put people of various occupations together for management .)
The solution is as follows ..
People * minutes les [100];
Here, people is a virtual base class. This array can be used to manage 100 instances of teacher, Doctor...
2> C ++ Solution
In fact, the above method can solve our problem well, but it will bring about pointer management problems, which is not promoted in C ++.
A good C ++ design should avoid using pointers directly. For new problems, our proxy class has emerged.
3> proxy
Our proxy class should solve two problems now. One is to close the pointer management, and the other is that it cannot affect the pure virtual parent class of the proxy.
The proxy class of a people is as follows .:
Class peoplesurrogate {
Public:
// Constructor
Peoplesurrogate (): p (0 ){}
Peoplesurrogate (const people & TP): p (Tp. Copy () {}// copy is a member function that copies itself to the people class.
Peoplesurrogate (const peoplesurrogate & PS): p (PS. P? PS. P-> copy: 0 ){}
// Of course, operator = () should also be implemented, which is similar to the copy structure.
~ Lelesurrogate ();
// Functions of people
Void look (){
P-> look ();
}
PRIVATE:
People * P;
};
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------