c**a 发帖数: 316 | 1 C++ coding standards 101:
50:
Make base class destructors public and virtual, or protected and nonvirtual
但是如果 dtor is protected, Base class can't be instantiated...
So dtor must be public and virtual..
所以我想作者是不是搞错了。。。
class A
{
protected:
~A();
}
int main()
{
A a;
A* p=new A();
return 1;
} |
X****r 发帖数: 3557 | 2 Some base classes are not supposed to be instantiated at all.
nonvirtual
【在 c**a 的大作中提到】 : C++ coding standards 101: : 50: : Make base class destructors public and virtual, or protected and nonvirtual : 但是如果 dtor is protected, Base class can't be instantiated... : So dtor must be public and virtual.. : 所以我想作者是不是搞错了。。。 : class A : { : protected: : ~A();
|
s***e 发帖数: 122 | 3 让dtor为protected和nonvirtual就是为了让基类不能被instantiated,但是又可以让
子类的dtor调用到吧。
nonvirtual
【在 c**a 的大作中提到】 : C++ coding standards 101: : 50: : Make base class destructors public and virtual, or protected and nonvirtual : 但是如果 dtor is protected, Base class can't be instantiated... : So dtor must be public and virtual.. : 所以我想作者是不是搞错了。。。 : class A : { : protected: : ~A();
|
c**a 发帖数: 316 | 4 恩。谢谢。
【在 s***e 的大作中提到】 : 让dtor为protected和nonvirtual就是为了让基类不能被instantiated,但是又可以让 : 子类的dtor调用到吧。 : : nonvirtual
|