In this short post I wanted to share a small but interesting thing I learnt. You probably know that in C++11 it is possible to require that no?ne must inherit from your class. You just declare your class as “final”: struct B final { int i; }; struct D : B { // ERROR int j; }; This feature is already implemented in new compilers. I know at least of three: Clang 3.0, GCC 4.7 and VC 11. I was often wondering why anyone would want to prohibit inheritance from one’s class; in C++. Recently I came across one good example where this is useful. Perhaps there are some good reasons to do that, which I always failed to understand or notice. I would be glad to learn about them. The one I found comes from the recent ISO C++ Committee’s mailing. The mailing is in general an interesting resource to learn about the development and the future of C++. You can find the pre-Portland mailing here. The proposal in question is N3407 (Proposal to Add Decimal Floating Point Support to C++). The author proposes the addition of three types that would represent decimal floating-point types: In contrast, if type
Advertisements
|
|
来自: astrotycoon > 《深度理解C 》