Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » What is a protected abstract virtual base pure virtual private destructor?

This thread is locked; no one can reply to it. rss feed Print
What is a protected abstract virtual base pure virtual private destructor?
Pradeepto Bhattacharya
Member #1,340
May 2001

Well I came across this line in somebody's quote at some website. I thought that it was a joke. But out of curiosity I did a Google. And woah!! The first result was bang on. I found this explanation -

Quote:

Q What is a protected abstract virtual base pure virtual private destructor? (Van Der Linden, Peter. Expert C Programming. Page 327)

A It is a pure virtual private destructor that is inherited from a protected abstract virtual base. In other words, a destructor function that can only be called by members or friends of the class (private), and is assigned a 0 (pure virtual) in the base class (abstract base) that declares it, and will be defined later / overriden in a derived class that shares the multiply-inherited base (virtual base) in a protected way.

class y : virtual protected x
{
private:
  ~y() = 0;
};

class z : protected y { };
Quote:

In this instance, ~y() is a protected abstract virtual base pure virtual private destructor of z.

Next half hour was like :o:o::):o::):o::) Zoinked!

Oke fine! I get it or perhaps not ! But please somebody tell me what is the use of such a construct ? Is there any use at all or it is just a hack to bother candidates in interviews ?? :P

Thank you in advance.

--
I vote for Pradeepto. - Richard Phipps
Hey; Pradeepto's alive! - 23yrold3yrold

A J
Member #3,025
December 2002
avatar

i would use it instead of a plunger, when my toilet is blocked, C++ reference books make a good alternative.

___________________________
The more you talk, the more AJ is right. - ML

Tobias Dammers
Member #2,604
August 2002
avatar

Ask one of the Finnish guys around here what the longest word in their language is, and they'll come up with quirks that are for finnish what the above is for C++. Anyway, who knows, there might be scenarios where you actually use such a monster.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

X-G
Member #856
December 2000
avatar

We can do that in Swedish, too. Finnish and Swedish both do concatenation rather than stacking, so we can create potentially infinitely long connected words. Of course, they're nonsensical and no one would use them, but we can do it. Example:

Buffer overrun = buffertöverskridning
Buffer overrun handler = buffertöverskridningshanterare
Buffer overrun handler exception = buffertöverskridningshanterarundantag
Buffer overrun handler exception error identification number = buffertöverskridningshanterarundantagsfelsidentifikationsnummer.

And so on.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Johan Halmén
Member #1,550
September 2001

But that's only connected words. In Finnish we can twist and stretch one single word. Beat that!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

Pradeepto Bhattacharya
Member #1,340
May 2001

Here is the link where I found the explanation.

Still looking for an answer though.

--
I vote for Pradeepto. - Richard Phipps
Hey; Pradeepto's alive! - 23yrold3yrold

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

Still looking for an answer though.

Don't. Should you ever find yourself using such a word, see a shrink. Should you ever find yourself using such a construct, revise your program layout.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

ReyBrujo
Moderator
January 2001
avatar

You know, you would not likely use it at all. Basically it is saying that the destructor can be called only by friends or members of the class, but that the class itself will not define the destructor, one of the children will define it.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Wetimer
Member #1,622
November 2001

No, actually. The fact being if you do that you'll never be able to define a destructor. All destructors from subclasses will attempt to call the destructor of the base class, and will have major problems.

<code>if(Windows.State = Crash) Computer.halt();</code>

Tobias Dammers
Member #2,604
August 2002
avatar

class BaseClass {
  private:
    virtual ~BaseClass() = 0;
};

class DerivedClass: public BaseClass {
  private:
    virtual ~BaseClass() { /* do stuff */ }
};

...dunno ...would this work?

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Wetimer
Member #1,622
November 2001

test.cpp:1: warning: `class BaseClass' only defines a private destructor and
   has no friends
test.cpp:8: error: destructor `BaseClass' must match class name `DerivedClass'
test.cpp:6: warning: `class DerivedClass' only defines a private destructor and

   has no friends
test.cpp: In destructor `virtual DerivedClass::~DerivedClass()':
test.cpp:3: error: `BaseClass::~BaseClass()' is private
test.cpp:8: error: within this context

<code>if(Windows.State = Crash) Computer.halt();</code>

Go to: