Here I paste a simple address book/telephone book. The linker spits the following error:
g++.exe derived2.o -o "Derived2.exe" -L"C:/Dev-Cpp/lib"
derived2.o(.text$_ZN2ABD2Ev[AB::~AB()]+0x3a):derived2.cpp: undefined reference to `vtable for AB'
derived2.o(.text$_ZN2ABC2ESsSsSs[AB::AB(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x3d):derived2.cpp: undefined reference to `vtable for AB'
collect2: ld returned 1 exit status
make.exe: *** [Derived2.exe] Error 1
Execution terminated
I would be thankful for ideas on what is wrong..
#include <iostream>
#include <string>
#include <map>
#include <list>
using namespace std;
class TelB;
class AB { // Address Book
protected:
string name;
string address;
string land;
public:
virtual void add(list<TelB*>&);
virtual void del(list<TelB*>&);
virtual void show() const {
cout << "\n Name: " << name << "\n Address: " << address;
cout << "\n Land: " << land;
};
AB(string n, string a, string l){
name = (string) n;
address = (string) a;
land = (string) l;
}
virtual ~AB(){};
};
class TelB : public AB { // Telephone Book
private:
string number;
enum Type { Mobile = 1, Static = 2 };
Type Tel_type;
public:
virtual void add(list<TelB*>&);
virtual void del(list<TelB*>&);
virtual void show() const;
TelB(string n, string a, string l, string num, int type)
:AB(n, a, l) {
string tmp;
string MobileBG = "888", MobileDE = "177";
string StaticBG = "00359", StaticDE = "0049";
// Adding pre-dial stuff for the numbers(for convenience)
if(l == "Bulgaria")
if(type == 1)
tmp = StaticBG + MobileBG;
else
tmp = StaticBG;
if(l == "Germany")
if(type == 1)
tmp = StaticDE + MobileDE;
else
tmp = StaticDE;
number = tmp + " / " + num;
}
virtual ~TelB(){};
};
void TelB::add(list<TelB*>& PB) {
string n, a, l, num;
short t;
cout << "\n Please input name: "; cin >> n;
cout << "\n Please input address: "; cin >> a;
cout << "\n Please input land(Bulgaria or Germany)?: "; cin >> l;
cout << "\n Please input number: "; cin >> num;
cout << "\n What type of phone is this(1 - Mobile, 2 - Static): "; cin >> t;
TelB* new_entry = new TelB(n, a, l, num, (Type) t);
PB.push_front(new_entry);
delete new_entry;
}
void TelB::show() const {
AB::show();
cout << "\n Number: " << number;
cout << "\n Phone type: " << Tel_type;
}
void TelB::del(list<TelB*>& PB){
cout << "\n Please input an entry number to be removed: ";
long n, j=0;
cin >> n;
for(list<TelB*>::iterator I=PB.begin(); ;++I) {
j++;
if(n == j) {
PB.erase(I);
cout << "\n Entry deleted.\n";
break;
}
if(I==PB.end()) {
cout << "\n No such entry found...\n";
break;
}
}
}
short printmenu(void) {
cout << "\n\n\n";
cout << "\n 1. Add to phone book";
cout << "\n 2. Delete from phone book";
cout << "\n 3. Show entries";
cout << "\n 4. Quit";
cout << "\n Your Choice?: ";
short choice;
cin >> choice;
return choice;
}
void print_list(list<TelB*>& w) {
long j=0;
for(list<TelB*>::const_iterator I=w.begin(); I!=w.end(); ++I) {
j++; (*I)->show();
cout << "\n Entry number: " << j << endl;
}
}
int main(void) {
TelB Default("Me", "Some Address", "Bulgaria", "777877", 2);
list<TelB*> Phone_book;
for(;;) {
switch(printmenu()) {
case 1: Default.add(Phone_book);
break;
case 2: Default.del(Phone_book);
break;
case 3: print_list(Phone_book);
break;
case 4: return 1;
break;
default: cout << "\n Please choose a number from 1 to 4 for your "
<< "corresponding choice." << endl;
break;
}
}
return 0;
}
Thanks!