![]() |
#2
生命太短暂2020-05-07 19:07
|

个人感觉加了friend不是朋友关系而是黑社会大哥与小第关系,好像在说,我是你大哥你的成员就是我的....
现在呢?我想让sub也当大哥,让subd里的b_放在sub里,解解sub想当大哥的隐?怎么做啊?
#include <iostream>
using namespace std;
class Subd;
class Sub
{
int a_=6;
public:Sub (){}
Sub(int a):a_(a){}
void output(/*const Subd&cn*/)//加了注释的地方是报错的
{
cout<<a_<</*cn.b_<<*/endl;
}
int cheng()
{
return (a_*a_);
}
friend class Subd;
};
class Subd
{
int b_=3;
public:
Subd (){}
void output( Sub&tn)
{
cout<<b_<<" "<<tn.a_<<" "<< tn.cheng() <<endl;
} /*friend class Sub;*/
};
int main()
{ Sub tex;tex.output();
Subd tex1;tex1.output(tex);
}