1
template
<
typename _Ty
>
2 class FinalTemplate
3 {
4 private :
5 FinalTemplate()
6 {
7 }
8 ~ FinalTemplate()
9 {
10 }
11 friend _Ty;
12 };
13 class FinalClass: virtual public FinalTemplate < FinalClass >
14 {
15 public :
16 FinalClass()
17 {
18 }
19 ~ FinalClass()
20 {
21 }
22 };
23 /* error: Final class not deriveable */
24
25 class DerivedClass: public FinalClass
26 {
27 public :
28 DerivedClass()
29 {
30 }
31 ~ DerivedClass()
32 {
33 }
34 };
2 class FinalTemplate
3 {
4 private :
5 FinalTemplate()
6 {
7 }
8 ~ FinalTemplate()
9 {
10 }
11 friend _Ty;
12 };
13 class FinalClass: virtual public FinalTemplate < FinalClass >
14 {
15 public :
16 FinalClass()
17 {
18 }
19 ~ FinalClass()
20 {
21 }
22 };
23 /* error: Final class not deriveable */
24
25 class DerivedClass: public FinalClass
26 {
27 public :
28 DerivedClass()
29 {
30 }
31 ~ DerivedClass()
32 {
33 }
34 };
当 DerivedClass 不定义默认构造函数时,虽然能够编译通过,但是无法实例化