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 -
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 { };
In this instance, ~y() is a protected abstract virtual base pure virtual private destructor of z.
Next half hour was like 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 ??
Thank you in advance.
i would use it instead of a plunger, when my toilet is blocked, C++ reference books make a good alternative.
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.
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.
But that's only connected words. In Finnish we can twist and stretch one single word. Beat that!
Here is the link where I found the explanation.
Still looking for an answer though.
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.
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.
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.
class BaseClass { private: virtual ~BaseClass() = 0; }; class DerivedClass: public BaseClass { private: virtual ~BaseClass() { /* do stuff */ } };
...dunno ...would this work?
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