>这是不可能的。创建成员函数 friend 声明,可以将全局函数或整个类声明为friend,另请参见: C ++ ref,友谊和继承。It's not possible to create member function friend declarations, you can either declare global functions or whole classes as friend, see also: C++ ref, Friendship and inheritance.一般来说,使用 friend ,因为它强烈地将类耦合在一起。更好的解决方案是耦合接口(不需要公开显示)。 在极少数情况下,它可能是一个好的设计决策,但几乎总是适用于内部细节。In general it's not a good design idea to use friend at all, because it strongly couples the classes together. The better solution will be to couple interfaces (which don't need to be publicly visible anyways).In rare cases it might be a good design decision but that almost always applies to internal details. 这篇关于在C ++中使用friend函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 15:22
查看更多