开发者

c++, protected abstract virtual base pure virtual private destructor

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

"If you think C++ is not o开发者_运维问答verly 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.


Scott Meyers has his answer also:

https://youtu.be/ltCgzYcpFUI?t=7m25s

c++, protected abstract virtual base pure virtual private destructor


Not sure of the original context, but my guess would be someone claiming that C++ is less complicated that a language like Java. Tom's point is that C++ has enough features to it that you can easily make a construct that is VERY complicated.


These words seem to make sense but not really.

Also stringing two different things together attributes in an attempt to over complicate things is a sign that author is just trying to confuse people to try and make a point that is not really there.

We should note that each situation is unique and you build your class hierarchy and destructors as required by the situation. Calling the language overcomplicated because it provides facility is silly. Its like saying what is the point of private inheritance. Yes normally you are not going to use it but there will be an occasion when it is nice to have.

Also I don't think of:

protected abstract virtual base pure virtual private destructor and when was the last time you needed one

I think:

  1. My class is abstract
  2. The destructor has to be virtual.
  3. But I don't need an implementation so its pure
  4. I will use protected inheritance


Basically, he just threw together a bunch of words and stuck them together without realizing they actually refer to different things, or often, the same thing.

protected abstract virtual base

Pretty simple.

class Base { // BASE
    virtual something() = 0; // ABSTRACT
};
class Derived : protected virtual Base { // PROTECTED VIRTUAL
};

pure virtual private destructor

Also pretty simple.

class Base { // BASE
private:
    virtual ~Base() = 0; // pure virtual, private, destructor
};
class Derived : Base {
};

Of course, pure virtual is the same as abstract.

It's quite clearly complete and total hyperbole written by someone who doesn't have a clue what he's talking about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜