Programming problem

DarkKnight

Golden Member
Apr 21, 2001
1,197
0
0
I keep on getting this error message when I try to compile my code:
ld:
Unresolved:
The virtual table '__vtbl_5Coach' for class 'Coach' is undefined, make sure that the first noninlined virtual member function is defined.


been spending a couples hours trying to fix this, but no luck. I'm pretty sure I'm declaring all the virtual member functions, have no idea what i should do. HOw can i figure out whats wrong?
 

DarkKnight

Golden Member
Apr 21, 2001
1,197
0
0
sry, here it is:



Coach.h
#ifndef COACH_H
#define COACH_H

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

using namespace std;

class Coach:public AMember
{

static const int CUR_YEAR = 2004;

public:

Coach(Name name_in = Name(), int year_in = CUR_YEAR,
string email_in = "NONE", NameList medal_in = NameList(),
int years_in = 0, bool former_in = false);

~Coach();
string classType() const;
Coach* duplicate() const;

NameList getMedalists() const;
int getYearsCoaching() const;
bool getFormerAthlete() const; // better name is "isFormerAthlete"
// but do NOT change this

private:
NameList medalists;
int yearsCoaching;
bool formerAthlete;

istream&amp; readin(istream&amp; input);
ostream&amp; writeout(ostream&amp; output) const;
};

#endif





Coach.cpp
#include "Coach.h"
#include "NameList.h"
#include <iostream>
#include <string>

using namespace std;

Coach::Coach(Name name_in, int year_in,
string email_in, NameList medal_in,
int years_in, bool former_in):AMember(name_in, year_in, email_in)
{
medalists = medal_in;
yearsCoaching = years_in;
formerAthlete = former_in;
}

Coach::~Coach()
{

}

string Coach::classType() const
{
return "Coach";
}

Coach* Coach::Duplicate() const
{
Coach *newCoach;

newCoach = new Coach;
*newCoach = *this;

return newCoach;
}

NameList Coach::getMedalists() const
{
return medalists;
}

int Coach::getYearsCoaching() const
{
return yearsCoaching;
}

bool Coach::getFormerAthlete() const
{
return formerAthlete;
}

istream&amp; Coach::readin(istream&amp; input)
{
string former;
input >> yearsCoaching;
input >> former;
if (former == "ATHLETE")
formerAthlete = true;
else
formerAthlete = false;
input >> medalists;
return input;
}

ostream&amp; Coach::writeout(ostream &amp;output) const
{
output << "Years Coaching: " << yearsCoaching;
if (formerAthlete)
output << " (former athlete)";
output << endl;
if (medalists.size() > 0)
output << "Medalists:"<< endl << medalists;
else
output << "Medalists:" << endl << "none" << endl;
return output;
}

AMember.h

#ifndef AMEMBER_H
#define AMEMBER_H

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

class AMember
{
friend std::istream&amp; operator>>(std::istream&amp; input, AMember &amp;target);
friend std::eek:stream&amp; operator<<(std::eek:stream&amp; output, const AMember &amp;src);

static const int CUR_YEAR = 2004;

public:
AMember(Name name_in = Name(), int year_in = CUR_YEAR,
std::string email_in = "NONE");
virtual ~AMember();

virtual std::string classType() const = 0;
virtual AMember* duplicate() const = 0;

Name getName() const;
Name getKey() const;
int getYear() const;
std::string getEmail() const;

static int getCurYear();

protected:
// moved here - see FAQ
virtual std::istream&amp; readin(std::istream&amp; input) =0;
virtual std::eek:stream&amp; writeout(std::eek:stream&amp; output) const =0;

private:
Name name;
int year;
std::string email;
};

#endif

AMember.cpp

#include "AMember.h"
#include <string>

using namespace std;

//default constructor for AMember

//Returns name of member
AMember::AMember(Name name_in, int year_in,
std::string email_in)
{
name = name_in;
year = year_in;
email = email_in;
}

AMember::~AMember()
{
delete this;
}
Name AMember::getName() const
{
return name;
}

//returns the name of member
Name AMember::getKey() const
{
return name;
}

//returns year member joined
int AMember::getYear() const
{
return year;
}

//returns member email address
string AMember::getEmail() const
{
return email;
}


//reads in AMember information from input stream
istream&amp; operator>>(istream&amp; input, AMember &amp;target)
{
input>>target.name >> target.year >> target.email;
return target.readin(input);
}

//outputs AMember information to output stream
ostream&amp; operator<<(ostream&amp; output, const AMember &amp;src)
{
output << src.name << "Member Since: "
<< src.year << ", " << "Email: " << src.email <<endl;
return src.writeout(output);
}


//returns the current year for the AMember
int AMember::getCurYear()
{
return CUR_YEAR;
}

 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
It's been a while since I've had to deal with the nitty gritty of C++ specs, but 2 things to try:

1) Make the 4 pure virtual functions from your base class virtual in the subclass.
2) Change the duplicate function in Coach to return AMember *

Those are a couple of items that the compiler might not like, but I'm not positive. If neither of those happen to work, would have to look a little deeper.