Hi to everybody! Here I paste some simple exercise code that I wrote. The errors are pasted from the compiler log at the end of the source code. The add() function looks ok to me and I can't understand what the compiler wants from me :o Thanks!
#include <iostream>
#include <string>
#include <list>
using namespace std;
class Worker {
protected:
string fname, lname;
string address;
unsigned number;
public:
inline virtual void add(DepBoss* new_boss, list<Worker*>& M) = 0;
inline virtual void print(void) {
cout << " Name: " << fname << " " << lname;
cout << " Address: " << address;
cout << " Number: " << number;
}
Worker(string fn, string ln, string addr, unsigned n)
:fname((string)fn), lname((string)ln), address((string)addr) {
if(n < 0)
throw "Scheisse in Worker Constructor!";
else
number = n;
};
virtual ~Worker(){};
};
class DepBoss : public Worker {
private:
short level;
int podchineni;
public:
inline virtual void add(DepBoss* new_boss, list<Worker*>& M);
inline virtual void print(void);
DepBoss(string fn, string ln, string addr, unsigned n, short lvl, int pod)
:Worker(fn, ln, addr, n) {
if(lvl < 0 && lvl > 5)
throw "Scheisse in DepBoss Constructor(lvl)";
else
level = lvl;
if(pod < 0 && pod > 100)
throw "Scheisse in DepBoss Constructor(pod)";
else
podchineni = pod;
};
virtual ~DepBoss(){};
};
inline void DepBoss::add(DepBoss* new_boss, list<Worker*>& M) {
M.push_front(new_boss);
}
void DepBoss::print(void) {
cout << " DepBosses:" << endl;
Worker::print();
cout << "\n Level of clearance: " << level;
cout << "\n Number of podchineni: " << podchineni;
}
void print_list(list<Worker*>& w) {
for(list<Worker*>::const_iterator I=w.begin(); I!=w.end(); ++I)
(*I)->print();
}
int main(void) {
static string fn, ln, addr;
static unsigned num;
static short lvl;
static int pod;
try {
cout << "\n Please, input first name: "; cin >> fn;
cout << "\n Please, input last name : "; cin >> ln;
cout << "\n Please, input DepBoss' address: "; cin >> addr;
cout << "\n Please, input DepBoss' number: "; cin >> num;
cout << "\n Please, input DepBoss' clearance level: "; cin >> lvl;
cout << "\n Please, input DepBoss' number of podchineni: "; cin >> pod;
DepBoss Boss("Toni", "Montana", "Cubastr. 13", 1, 0, 50);
list<Worker*> L;
L.push_front(&Boss);
DepBoss* Boss2 = new DepBoss(fn, ln, addr, num, lvl, pod);
Boss2->add(Boss2, L);
print_list(L);
delete Boss2;
}
catch(char *str) {
cout << "\n Erroroneus inputs given: " << str << ".... Exiting." << endl;
return -1;
}
return 0;
}
/*
tbook.cpp:13: error: variable or field `add' declared void
tbook.cpp:13: error: `add' declared as a `virtual' field
tbook.cpp:13: error: `add' declared as an `inline' field
tbook.cpp:13: error: expected `;' before '(' token
make.exe: *** [tbook.o] Error 1
Execution terminated
*/