[class.dtor]/1包含以下句子:
Each decl-specifier of the decl-specifier-seq of a destructor declaration (if any) shall be
friend
,inline
, orvirtual
.
我真的很想看到一个使用带有
friend
的析构函数的示例。说明符。
最佳答案
假设您要允许 A
类的私有(private)成员用于类B
.没问题,你声明B
作为里面的 friend A
.
进一步假设您希望将使用限制为 B
的析构函数而已。因此,您只需声明 B
的析构函数作为 friend :
struct A
{
private:
// some private stuff
friend B::~B();
};
见 this example on ideone .
关于c++ - 在析构函数中使用 `friend` 说明符的示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49650224/