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

前端 未结 5 1653
长情又很酷
长情又很酷 2020-12-25 13:32

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 d

相关标签:
5条回答
  • 2020-12-25 14:11

    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.

    0 讨论(0)
  • 2020-12-25 14:14

    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
    0 讨论(0)
  • 2020-12-25 14:15

    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.

    0 讨论(0)
  • 2020-12-25 14:23

    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 讨论(0)
  • 2020-12-25 14:27

    Scott Meyers has his answer also:

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

    0 讨论(0)
提交回复
热议问题