In my opinion, the reason why C + + is suitable for architectural design is that it can be programmed for the future. For example, you can use Public/protected/private to restrict the access of a derived class to a base class member, you can define an abstract class that requires an interface that a derived class must implement, and so on.
When we declare/define a virtual function, the derived class can choose to override this virtual function or choose not to overwrite it. In this regard, C + + also provides the necessary methods to require derived classes to override some methods, which can also be seen as a programming for the future.
Pure virtual function
This is not a new technology, and the function is very simple: once a base class declares a pure virtual function, its derived classes must override this function when instantiated.
The Sub::f1 () method is commented out in this example, so a compilation error occurs on line 27th.
Final specifier
Generally speaking, there should be a means of prohibiting coverage if there is a requirement to cover the method. But I don't know why, this feature was introduced into the c++11. The use of the method is simple: Just add the final specifier after the function declaration.
The code basically does not change, except that the BASE::F1 () declaration is replaced with the final specifier. If the Sub::f1 () method is defined, a compile error is generated.
Author's opinion
Based on the author's personal understanding, this article puts the pure virtual function and the final specifier together for illustration. If there are inaccuracies, please add and correct them.
Related articles:
Details c++11 final and override specifiers
Auto and Decltype differences and linkages in c++11 new features
Related videos:
C Language Tutorials