受保护的抽象虚拟基础纯虚拟私有析构函数

受保护的抽象虚拟基础纯虚拟私有析构函数

本文介绍了c ++,受保护的抽象虚拟基础纯虚拟私有析构函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果你认为C ++不太复杂,那么什么是受保护的抽象虚拟基础纯虚拟私人析构函数和什么时候是你最后一次需要一个?
- Tom Cargill

解决方案

我们通过 protected virtual 使用的抽象基类的一部分私有纯虚拟析构函数 em>继承。 。

  class Base 
{
private:
virtual〜Base()= 0; / * A * /
};

class Derived:protected virtual Base
{
private:
〜Derived(){.......} / * B * /
};

从标签B的角度看,标签A处的行是受保护的抽象虚拟基纯虚拟私有析构函数,



这三个部分中的每一个都有单独的使用。我不知道一个设计模式,需要上述三个部分,但没有什么阻止他们一起使用。


So, I found this quote today, can anyone explain?

"If you think C++ is not overly complicated, just what is a protected abstract virtual base pure virtual private destructor and when was the last time you needed one?— Tom Cargill"

解决方案

I believe it is a private pure virtual destructor (I think that part is self-explanatory) that is part of an abstract base class, which you've used through protected virtual inheritance. .

 class Base
 {
    private:
        virtual ~Base() = 0;   /* A */
 };

 class Derived : protected virtual Base
 {
    private:
     ~Derived () {.......}    /* B */
 };

From the point of view of tag B, the line at tag A is a "protected abstract virtual base pure virtual private destructor",

Each of those three parts has its uses individually. I do not know of a design pattern that requires all three of the above parts, but there's nothing preventing their uses together.

这篇关于c ++,受保护的抽象虚拟基础纯虚拟私有析构函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:32