[class.dtor]/1 contains the following sentence:
Each decl-specifier of the decl-specifier-seq of a destructor declaration (if any) shall be
friend
,inline
, orvirtual
.
I'm really interested in seeing an example of the use of a destructor with a friend
specifier.
Suppose you want to allow private members of class A
to be used in class B
. No problem, you declare B
as a friend inside A
.
Suppose further that you want to restrict the usage to B
's destructor only. Thus, you only declare B
's destructor as a friend:
struct A
{
private:
// some private stuff
friend B::~B();
};
See this example on ideone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With