由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++: protect dtor
相关主题
some C++ interview questions请问关于c++实现singleton的问题?
问个虚函数的作用含泪流血裸奔完整代码回答C++弱问题
Help! Virtual DestructorC++ 书推荐
C++一个类中多个thread的问题急问:compile and build dependency
C++问题,confusing...find bugs of c++ codes
一个C++的问题老调重弹 virtual destructor
one question about operator delete没有经过构造函数???
一道c++的考古题heap 和 stack问题
相关话题的讨论汇总
话题: dtor话题: c++话题: nonvirtual话题: base
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
heap 和 stack问题C++问题,confusing...
C++编程问题,关于static member 在class中的使用,谢谢一个C++的问题
请教一个c++ throw exception 问题one question about operator delete
我这个C++程序有没有什么问题啊?请指点。。。谢谢。。。一道c++的考古题
some C++ interview questions请问关于c++实现singleton的问题?
问个虚函数的作用含泪流血裸奔完整代码回答C++弱问题
Help! Virtual DestructorC++ 书推荐
C++一个类中多个thread的问题急问:compile and build dependency
相关话题的讨论汇总
话题: dtor话题: c++话题: nonvirtual话题: base