tags:

views:

122

answers:

4

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"

+2  A: 

I believe it a private pure virtual destructor (I think that part is self-explanatory) that is part of a 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 it uses individually. I know of no design pattern which requires all three, but there's nothing preventing their use together.

James Curran
That's a compile error, right? Because in virtual inheritance, the destructor for the virtual base must be called by the most-derived destructor, but `~Derived()` has no access to `~Base()`. (NB: Just because `~Base()` is *pure virtual* doesn't mean there is no body.)
Ben Voigt
+1  A: 

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.

awithrow
A: 

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.

DeadMG
I think Tom Cargill has a reasonable idea what the words mean. See: http://www.amazon.com/C-Programming-Style-Tom-Cargill/dp/0201563657
janm
A: 

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
Martin York