Code:
// tv.h Pg 733 prblm #1
#ifndef _TV_H_
#define _TV_H_
class Tv
{
friend class Remote;
public:
// Remote can access TV private parts
enum {Off, On};
enum {MinVal,MaxVal=20};
enum {Antenna,Cable};
enum {TV,VCR};
Tv(int s=Off, int mc=100): state(s), volume(5), maxchannel(mc),
channel(2), mode(Cable), input(TV){}
void onoff(){state=(state==On)? Off: On;}
bool ison() const {return state==On;}
bool volup();
bool voldown();
void chanup();
void chandown();
void set_mode() {mode=(mode==Antenna)? Cable:Antenna;}
void set_input() {input=(input==TV)? VCR :TV;}
void settings() const; // display all settings
bool Tv::set_state(Remote & r);
private:
int state;
int volume;
int maxchannel;
int channel;
int mode;
int input;
};
class Remote
{
friend class Tv;
private:
int mode;
int state;
public:
enum{Normal,Interactive};
Remote(int m=Tv::TV, int s=Normal): mode(m), state(s){}
bool volup(Tv & t) {return t.volup();}
bool voldown(Tv & t) {return t.voldown();}
void onoff(Tv & t) {t.onoff();}
void chanup(Tv & t) {t.chanup();}
void chandown(Tv & t) {t.chandown();}
void set_chan(Tv & t, int c) {t.channel=c;}
void set_mode(Tv & t) {t.set_mode();}
void set_input(Tv & t) {t.set_input();}
void settings() const {cout << "Remote is in "
<< (state==Normal? "Normal" : "Interactive")<< " mode.\n";}
};
inline bool Tv::set_state(Remote & r)
{
if (ison())
{
r.state=(r.state==Normal)? Interactive:Normal;//errors here
return 1;
}
else
return 0;
};
#endif
errors
Building Makefile: "C:\Dev-C++\Makefile.win"
Executing make clean
rm -f tv.o use_tv.o tv.exe
g++.exe -c tv.cpp -o tv.o -I"C:\Dev-C++\include" -I"C:\Dev-C++\include\g++-3" -I"C:\Dev-C++\include" -g3
In file included from tv.cpp:4:
tv.h: In method `bool Tv::set_state(Remote &)':
tv.h:63: `Normal' undeclared (first use this function)
tv.h:63: (Each undeclared identifier is reported only once
tv.h:63: for each function it appears in.)
tv.h:63: `Interactive' undeclared (first use this function)
make.exe: *** [tv.o] Error 1
Execution terminated
it seems my problem is the enumeration type not being in scope and that the easy way to fix it would be to add the enumeration type to the tv class but this seems redundant. One of the requirements of the problem is to add a state variable member to the Remote class that describes whether the remote control is in normal or interactive mode. How should I fix this error?