Tak jak w temacie. Podczas próby kompilacji poniższego kodu dostaje czterokrotną informacje o błędzi linkera 2005 .
#pragma once
#include <iostream>
//deklaracja wyprzedzajaca
class Tv;
class Remote
{
private:
int mode;
int status;
public:
friend class Tv;
enum { Normal, Interactive };
enum {Off,On};
enum {MinVal,MaxVal = 20};
enum {Antenna, Cable};
enum {TV,DVD};
Remote(int m = TV) : mode(m) {}
bool _volup(Tv & t);
void _onoff(Tv &t);
void _chanup(Tv &t);
void _chandown(Tv &t);
void _set_chan(Tv &t, int c);
void _set_mode(Tv &t);
void _set_input(Tv &t);
void _show_status();
};
class Tv
{
public:
friend class Remote;
enum { Off, On };
enum { MinVal, MaxVal = 20 };
enum { Antenna, Cable };
enum { TV, DVD };
Tv(int s = Off, int mc = 125) :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) ? DVD : TV;
}
void setting() const; //wyswietla wszystkie ustawienia
void set_remote_status(Remote & r);
private:
int state;
int volume;
int maxchannel;
int channel;
int _mode;
int input;
};
bool Tv::volup()
{
if (volume < MaxVal)
{
volume++;
return true;
}
else
return false;
}
bool Tv::voldown()
{
if (volume > MinVal)
{
volume--;
return true;
}
else
return false;
}
void Tv::chanup()
{
if (channel < maxchannel)
{
channel++;
}
else
channel = 1;
}
void Tv::chandown()
{
if (channel > 1)
{
channel--;
}
else
channel = maxchannel;
}
void Tv::setting() const
{
using std::cout;
using std::endl;
cout << "Telewizor jest " << (state == Off ? "Wylaczony" : "Wlaczony") << endl;
if (state == On)
{
cout << "Glosnosc = " << volume << endl;
cout << "Program = " << channel << endl;
cout << "Tryb = " << (_mode == Antenna ? "antena" : "kabel") << endl;
cout << "Wejscie = " << (input == TV ? "TV" : "DVD") << endl;
}
}
void Tv::set_remote_status(Remote & r)
{
if (state == On) { (r.mode == Remote::Normal) ? r.mode = Remote::Interactive : r.mode = Remote::Normal; }
else
std::cout << "Telewizor musi byc wlaczony.\n";
}
inline bool Remote::_volup(Tv & t)
{
return t.volup();
}
inline void Remote::_onoff(Tv & t)
{
t.onoff();
}
inline void Remote::_chanup(Tv & t)
{
t.chanup();
}
inline void Remote::_chandown(Tv & t)
{
t.chandown();
}
inline void Remote::_set_chan(Tv & t, int c)
{
t.channel = c;
}
inline void Remote::_set_mode(Tv & t)
{
t.set_mode();
}
inline void Remote::_set_input(Tv & t)
{
t.set_input();
}
inline void Remote::_show_status()
{
std::cout << "Pilot pracuje w trybie: " << (status == Normal) ? "Normal" : "Interactive";
}