So I am getting the below error messages with seem to do with vtable. I would assume this is in relation to Virtual functions. I'm not sure what i'm doing wrong here or even the correct corse of action. HELP :-) ?

Ld /Users/krisarmstrong/Library/Developer/Xcode/DerivedData/CS215Lab4-cyvyxpagepfuqhdusjdgbpjctcis/Build/Products/Debug/CS215Lab4 normal x86_64
cd /Users/krisarmstrong/Documents/XCodeProjects/CS215Lab4
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang++ -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/krisarmstrong/Library/Developer/Xcode/DerivedData/CS215Lab4-cyvyxpagepfuqhdusjdgbpjctcis/Build/Products/Debug -F/Users/krisarmstrong/Library/Developer/Xcode/DerivedData/CS215Lab4-cyvyxpagepfuqhdusjdgbpjctcis/Build/Products/Debug -filelist /Users/krisarmstrong/Library/Developer/Xcode/DerivedData/CS215Lab4-cyvyxpagepfuqhdusjdgbpjctcis/Build/Intermediates/CS215Lab4.build/Debug/CS215Lab4.build/Objects-normal/x86_64/CS215Lab4.LinkFileList -mmacosx-version-min=10.7 -o /Users/krisarmstrong/Library/Developer/Xcode/DerivedData/CS215Lab4-cyvyxpagepfuqhdusjdgbpjctcis/Build/Products/Debug/CS215Lab4

Undefined symbols for architecture x86_64:
"vtable for telnumber", referenced from:
telnumber::telnumber() in TelephoneNumber.o
telnumber::telnumber(std::string, std::string, std::string) in TelephoneNumber.o
telnumber::~telnumber() in TelephoneNumber.o
"vtable for worknumber", referenced from:
worknumber::worknumber() in WorkTelephoneNumber.o
worknumber::worknumber(std::string, std::string, std::string, std::string) in WorkTelephoneNumber.o
worknumber::~worknumber() in WorkTelephoneNumber.o
"vtable for billnumber", referenced from:
billnumber::billnumber() in BillingTelephoneNumber.o
billnumber::billnumber(std::string, std::string, std::string, std::string, int) in BillingTelephoneNumber.o
billnumber::~billnumber() in BillingTelephoneNumber.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


"vtable for telnumber", referenced from:


telnumber::telnumber() in TelephoneNumber.o


telnumber::telnumber(std::string, std::string, std::string) in TelephoneNumber.o


telnumber::~telnumber() in TelephoneNumber.o


"vtable for worknumber", referenced from:


worknumber::worknumber() in WorkTelephoneNumber.o


worknumber::worknumber(std::string, std::string, std::string, std::string) in WorkTelephoneNumber.o


worknumber::~worknumber() in WorkTelephoneNumber.o


"vtable for billnumber", referenced from:


billnumber::billnumber() in BillingTelephoneNumber.o


billnumber::billnumber(std::string, std::string, std::string, std::string, int) in BillingTelephoneNumber.o


billnumber::~billnumber() in BillingTelephoneNumber.o


ld: symbol(s) not found for architecture x86_64


clang: error: linker command failed with exit code 1 (use -v to see invocation)

//Lab4.cpp

#include <iostream>
#include "BillingTelephoneNumber.h"
#include "TelephoneNumber.h"
#include "WorkTelephoneNumber.h"
//and then main

ostream& operator << (ostream &out, telnumber &tn)
{
	tn.printtostream(out);
	return out;	
}


int main()
{
	telnumber yournumber;
	telnumber paul("719","590","6768");
	telnumber bob("719","590", "6729");
	worknumber csstaff1 ("719","590","6732","Book Store");
	worknumber csstaff2 ("212","371","6940","Borland C++ Guru");
	worknumber csstaff3 ("405","612","3433","Visual C++ Expert");
	billnumber csdept ("719","590","6850","Dean of CS");
	billnumber library ("719","598","6708","Librarian");
	billnumber reception ("719","598","0200","Receptionist",35);
	cout << "Testing the overladen << operator with the virtual" << "printtostream()\n\n";
	cout << "The telephone numbers are: \n" << endl;
	cout << yournumber << endl;
	cout << paul << endl;
	cout << bob << endl;
	cout << "The working telephone numbers are: \n" << endl;
	cout << csstaff1 << endl;
	cout << csstaff2 << endl;
	cout << csstaff3 << endl;
	cout << "The billing telephone numbers are: \n" << endl;
	cout << csdept << endl;
	cout << library << endl;
	cout << reception << endl;
	cout << "Here endeth the hierarchy of the telephone!" << endl;
	
	return 0;
}

//TelephoneNumber.h
#ifndef TelephoneNumber_h
#define TelephoneNumber_h
#include <iostream>        
#include <string>
using namespace std;      

class telnumber
{
public:
	telnumber();
	telnumber (string i_npa, string i_nxx, string i_line);
	~telnumber();
	void setnpa (string newnpa);
	void setnxx (string newnxx);
	void setline (string newline);
	string getnpa();
	string getnxx();
	string getline();
	virtual void printtostream(ostream& out);
	
private:
	string npa;
	string nxx;
	string line;
	
};
#endif


//TelephoneNumber.cpp
#include <iostream>
#include <string>
#include "TelephoneNumber.h"

using namespace std;


telnumber::telnumber()

{
	string npa="";
	string nxx="";
	string line="";
}

telnumber::telnumber(string i_npa, string i_nxx, string i_line)
{
	
}

void telnumber::setnpa (string newnpa)
{
	npa=newnpa;
}

void telnumber::setnxx (string newnxx)
{
	nxx=newnxx;
}

void telnumber::setline (string newline)
{
	line=newline;
}
string telnumber::getnpa()
{
	return (npa);
}

string telnumber::getnxx()
{
	return (nxx);
}

string telnumber::getline()
{
	return (line);
}


telnumber::~telnumber()
{
	cout << "Destructor For Telephone Number" << endl;
}


//WorkTelephoneNumber.h
#ifndef WorkTelephoneNumber_h
#define WorkTelephoneNumber_h                         
#include <iostream>        
#include <string>
#include "TelephoneNumber.h"

using namespace std; 

class worknumber : public telnumber
{
public:
	worknumber();
	worknumber(string i_npa, string i_nxx, string i_line, string i_name);
	~worknumber();
	void setname(string newname);
	string getnewname();
	virtual void printtostream(ostream& out);
	
protected:
	string name;
	
};


#endif



//WorkTelephoneNumber.cpp

#include <iostream>
#include "WorkTelephoneNumber.h"
#include "TelephoneNumber.h"


worknumber::worknumber():

telnumber("","",""),  name ("")
{
}

worknumber::worknumber(string i_npa, string i_nxx, string i_line, string i_name): telnumber(i_npa, i_nxx, i_line)
{
	
}


void worknumber::setname(string newname)
{
	 name=newname;
}

string worknumber::getnewname()
{
	return (name);
}

void printtostream(ostream& out)
{

}

worknumber::~worknumber()
{
	cout << "Destructor For Work Number" << endl;
}

//BillingTelephoneNumber.h


#ifndef BillingTelephoneNumber_h
#define BillingTelephoneNumber_h

#include <iostream>        
#include <string>
#include "WorkTelephoneNumber.h"

using namespace std; 


class billnumber : public worknumber
{
public:
	billnumber();
	billnumber(string i_npa, string i_nxx, string i_line, string i_name, int numlines=0);
	~billnumber();
	void setnumlines();
	int getnumlines();
	virtual void printtostream(ostream& out);
	
protected:
	int numlines;
};

#endif


//billingTelephoneNumber.cpp
#include <iostream>
#include "BillingTelephoneNumber.h"
#include "WorkTelephoneNumber.h"
#include "TelephoneNumber.h"


billnumber::billnumber(): worknumber("","","","")
{
	
}

billnumber::billnumber(string i_npa, string i_nxx, string i_line, string i_name, int numlines): worknumber(i_npa, i_nxx, i_line, i_name)
{
	
}

void billnumber::setnumlines()
{
	numlines=0;
}

int billnumber::getnumlines()
{
	return (numlines);
}

billnumber::~billnumber()
{
	cout << "Destructor for Billing Number" << endl;
}
class telnumber
{
public:
	telnumber();
	telnumber (string i_npa, string i_nxx, string i_line);
	virtual ~telnumber(); // the destructor must be virtual
	void setnpa (string newnpa);
	void setnxx (string newnxx);
	void setline (string newline);
	string getnpa();
	string getnxx();
	string getline();
        
        // This must be defined or it should be declared as a pure virtual 
	virtual void printtostream(ostream& out);  
	
private:
	string npa;
	string nxx;
	string line;
	
};

And on line 190:

void < a class name here? >::printtostream(ostream& out)

Implement every non-pure virtual function in a class with at least one of them being defined out of line.
See: http://www.daniweb.com/software-development/cpp/threads/114299

This article has been dead for over six months. Start a new discussion instead.