友元类

1.友元类
class Tv{
public:
friend class Remote;
priavte:
int volume;
}
class Remote{
public:
bool volup(Tv &t){t.volume++;}
}
2.友元函数
class Tv{
friend void Remote::set_chan(Tv &t,int c);
}
3.友元函数使用前需声明
class Tv;//前向声明
class Remote{};//Tv类需要使用的方法原型放在这里
clss tv{};
//这里定义remote方法的定义

posted @ 2024-08-20 15:20  zhongta  阅读(14)  评论(0)    收藏  举报