Home > Back-end >  Two friends, Remote access to private members of Tv, and Tv cannot access Remote private members
Two friends, Remote access to private members of Tv, and Tv cannot access Remote private members

Time:03-30

# include
# # ifndef TVFM_H_
# define TVFM_H_
using std::cout;
using std::endl;
The class Remote;
The class Tv
{
Public:
Friend class Remote;
Enum state {OFF, ON};
Enum {MiniVal, very=20};
Enum {can Antenna, be used Cable};
Enum {} TV, DVD,
Tv (int a=OFF, int nc=100) : the state (a), maxchannel (nc), volume (5), the channel (2), mode (Cable), input (Tv) {};
Void onoff ();
Bool ison ();
Bool volup ();
Bool voldown ();
Void chanup ();
Void chandown ();
Void set_mode ();
Void set_input ();
Void setting ();
Void set_Remote (Remote& R);
Private:
Int state;
int volume;
Int maxchannel;
Int the channel;
Int mode;
Int input;
};
The class Remote
{
Public:
The friend class TV;
Enum state {OFF, ON};
Enum {MiniVal, very=20};
Enum {can Antenna, be used cable};
Enum {} TV, DVD,
Enum {normal, interact};
Private:
Int mode;
Int Remote_mode;
Public:
N=TV Remote (int) : mode (n), Remote_mode (normal) {};
Bool volup (Tv& T)
{
Return t.v olup ();
}
Bool voldown (Tv& T)
{
Return t.v oldown ();
}
Void onoff (Tv& T)
{
T.o noff ();
}
Void chanup (Tv& T)
{
Tc hanup ();
}
Void chandown (Tv& T)
{
Tc handown ();
}
Void set_mode (Tv& T)
{
T.s et_mode ();
}
Void set_input (Tv& T)
{
T.s et_input ();
}
Void set_chan (Tv& T, int n)
{
Tc hannel=n;
}
Void show_Remote_mode ()
{
cout <"Remote mode:" & lt; }
};


Void Tv: : set_Remote (Remote & amp; R)
{
R.R emote_mode=(r.R emote_mode==Remote: : normal? Remote: : interact: Remote: : normal);
}

# endif

Above is the code, in VS2019 tip Remote: : Remote_mode inaccessible,
The great god answers,
  • Related