We all know that object-oriented programming has three features: encapsulation, inheritance, polymorphism. Polymorphism plays an important role in object-oriented programming.
 
How is this polymorphism achieved? There is usually a base class that contains some specific interfaces that are overloaded by subclasses of the class, using pointers to the base class, or referencing objects that point to subclasses, so that the function of calling the corresponding function of the subclass can be implemented; This phenomenon is called polymorphism.
 
What are the characteristics of these polymorphic states?
 
1. It is bound. There is a base class, where some interfaces exist, and subclasses must overload these interfaces, which is bound.
 
2. It is dynamic. These function invocation mechanisms are dynamic, so that the execution period can be determined.
 
Polymorphic we can give it a new name, a polymorphic state, with the above two properties. So is there a polymorphic called static polymorphism? It does have a static polymorphism.
 
I think we must have guessed the characteristics of static polymorphism:
 
1. It is unbound: because the template mechanism is used, there is no so-called base class, so there is no need to bind.
 
2. It is static: because the virtual function mechanism is not adopted, all calls can be determined at compile time, so they are static.
 
How to achieve static polymorphism?
 
Class Circle
 {
 Public:
 Void Draw() const
 {
 Cout<<” Circle  Draw”<<endl;
 }
 }
 Class Line
 {
 Public:
 Void Draw() const
 {
 Cout<<” Line  Draw”<<endl;
 }
 }
 Template<typename T>
 Void DrawGeoObj(T const & obj)
 {
 Obj.Draw();
 }
 Int main(int *argc, char *argv[])
 {
 Circle c1;
 Line l1;
 DrawGeoObj(c1);// A
 DrawGeoObj(l1);// B
 }
 
At this point A, b two sentences can be considered as static polymorphism.
 
At this point you might think that this is nothing polymorphic, just a template function. Well, let me give you one more example.
 
We know that the bridge pattern in bridge mode (see design pattern) is generally implemented in the following way: