I'm getting a LNK 2019 and 2001 error every time I compile. LNK2019 states:
public: __thiscall ColMbr::ColMbr(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0ColMbr@@QAE@IV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Alumni::Alumni(unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Alumni@@QAE@IV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHH0@Z
So there is some kind of error linking ColMbr class with Alumni. LNK2011 says:
"public: virtual void __thiscall Alumni::addClass(unsigned int,unsigned int)" (?addClass@Alumni@@UAEXII@Z)
So there's an issue with my virtual function call. I understand that the LNK errors means there was a variable that needed to be declared that I missed but I don't see it. Firstly, the Alumni::addClass function is just there to make sure Alumni does not become an abstract class like ColMbr, which it's derived from. Secondly, all of the arguments in Alumni are defined and declared either in Alumni or in ColMbr.
If it was anything I'd say LNK2019 is probably a problem with my const unsigned int idNbr. I don't know what's wrong with LNK2001. Maybe I need to give the function a garbage purpose or something.
This is my header file followed by the cpp.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#ifndef _ColMbr
#define _ColMbr
class ColMbr
{
protected:
const unsigned int idNbr;
std::string name;
public:
ColMbr();
ColMbr(const unsigned int idNbr, std::string stdnt_name);
std::string setName(std::string stdnt_name);
virtual void display(void);
virtual void addClass(unsigned int credits, unsigned int gradePoint) = 0;
};
#endif // !1
std::string ColMbr::setName(std::string stdnt_name)
{
name = stdnt_name;
return name;
}
class Student : public ColMbr
{
private:
unsigned int credHrs, qualPts;
std::string degSought;
double GPA;
public:
Student(unsigned int idNbr, std::string name) : ColMbr (idNbr, name)
{
credHrs = 0;
qualPts = 0;
degSought = "Unspecified";
}
Student(const unsigned int idNbr, std::string stdnt_name, unsigned int credHrs1, unsigned int qualPts1, std::string newDegree) : ColMbr(idNbr,stdnt_name)
{
credHrs = credHrs1;
qualPts = qualPts1;
degSought = newDegree;
}
void setDegree(std:: string newDegree);
double getGPA(unsigned int credHrs, unsigned int qualPts);
void addClass(unsigned int newClass, unsigned int newQualPts)
{
credHrs = credHrs + newClass;
qualPts = qualPts + newQualPts;
}
void display(void)
{
std::cout << "This student is active." << std::endl <<"ID #: "
<< idNbr << std::endl << "Name: " << name << std::endl
<< "GPA: " << GPA << std::endl << "Major: " << degSought
<< std::endl;
}
};
void Student::setDegree(std:: string newDegree)
{
degSought = newDegree;
}
double Student::getGPA(unsigned int credHrs, unsigned int qualPts)
{
double credHrs1, qualPts1;
std::istringstream input(credHrs);
input >> credHrs1;
std::istringstream input1(qualPts);
input >> qualPts1;
GPA = qualPts1 / credHrs1;
return GPA;
}
#ifndef _Alumni
#define _Alumni
class Alumni : public ColMbr
{
private:
std::string degree;
int month, day, year;
public:
Alumni(const unsigned int idNbr, std::string stdnt_name, int gradMonth, int gradDay, int gradYear, std::string newDegree) : ColMbr(idNbr, stdnt_name)
{
degree = newDegree;
month = gradMonth;
day = gradDay;
year = gradYear;
}
void addClass(unsigned int credits, unsigned int gradePoint);
void display (void)
{
std::cout << "This student is an Alumni." << std::endl <<"ID #: "
<< idNbr << std::endl << "Name: " << name << std::endl
<< "Graduation Date: " << month << "/" << day << "/" << year
<< std::endl << "Major: " << degree << std::endl;
}
};
#endif
/**********************************************
#include <iostream>
#include <cstdlib>
#include "ColMbrs.h"
int main()
{
ColMbr *cMbr[4]; // array of base-class pointers
int i; // index to array
// Create some college members
cMbr[0] = new Student( 12345, "Steven DiFranco", 15, 33, "AA" );
cMbr[1] = new Alumni( 98765, "Don Green", 12, 15, 1978, "AAS" );
cMbr[2] = new Alumni( 24680, "Henry Thoreau", 5, 22, 1846, "AA" );
cMbr[3] = new Student( 13579, "Millenia Best" );
// display the array
cout << "All college members:\n";
for( i = 0; i < 4; ++i )
{
cMbr[i]->display(); // no need to check type field or cast
cout << endl;
}
// test addClass for student
cMbr[3]->addClass( 3, 12 );
cMbr[3]->display();
cout << endl;
system("PAUSE");
return 0;
}