因为CRect类并没有声明Compare类中的compareArea函数为友元函数,无法访问Compare类的私有成员变量m_length和m_width。而Compare类中的compareArea函数可以访问CRect类的私有成员变量m_length和m_width,是因为CRect类声明了Compare类中的compareArea函数为友元函数。

#include iostreamusing namespace std;class CRect;class Compare int m_length; int m_width;public void compareAreaconst Compare& r1 const Compare& r2 double s1 s2; s1 = r1m_le

原文地址: https://www.cveoy.top/t/topic/b1rw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录