This is the error message I keep getting. main.obj : error LNK2019: unresolved external symbol "public: __thiscall Defense::Defense(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)"
There was this as well:
fatal error LNK1120: 1 unresolved externals
I am using the right application in visual studio 2010. I have no Idea what to do. Here are the codes. Thank you in advance.
/*
* This is the main class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
#include <iostream>
#include <string>
#include "player.h"
#include "offense.h"
#include "defense.h"
#include <windows.h>
usingnamespace std;
int main(){
// Create the players for the team.
Offense player("Bob");
Defense player1("Jane");
Offense player2("Sai");
Defense player3("Chin");
Offense player4("Kali");
Player *team[5]; // Make a team of pointers to players.
// Question 1 - Why is there an '&' before the players on lines 29 to 33?
team[0] = &player;
team[1] = &player1;
team[2] = &player2;
team[3] = &player3;
team[4] = &player4;
// Set the player numbers
for(int i=0; i<5; i++)
team[i]->setNumber(i+10);
// Set the player minutes.
for(int i=0; i<5; i++)
team[i]->setMinutesPlayed(i*7+(i+1)*i+1);
// Question 2 - Why not use a loop for lines 45 to 49?
// Set the player's stats.
player.setYards(34);
player1.setTackles(5);
player2.setYards(23);
player3.setTackles(7);
player4.setYards(132);
// Print out each player's stats.
for(int i=0; i<5; i++)
team[i]->printStats();
system("pause");
}
//defense.cpp
//Defensive player class
#include "defense.h"
//The player's name
//Making the constructor for the defensive class.
//Calls the base constructor.
//Implementation. Sets the player's minutes.
//Should be in the base class due to nothing being specific to the defense.
void Defense::setMinutesPlayed(int minutes) //min=minutes
{
this->minutes=minutes;
}
//Defensive tackles
void Defense::setTackles(int tackles)
{
this->tackles=tackles;
}
//Printing player stats.
void Defense::printStats() const
{
Player::printStats();
cout<<"\tMinutes: " << minutes << "\tTackles: " << tackles << endl;
}
/*
* This is the header file for the player class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
// Question 3 - What do the #ifndef, #define and #endif preprocessor commands do in this file?
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>
#include <string>
usingnamespace std;
class Player{
private:
string name; // The player's name, notice it's private, Question 4 - What does this mean you have to do?
protected: // Question 5 - Why does number have to be private.
int number; // The player's number.
int minutes; // The number of minutes the player is in the game.
public:
/*
* This is the constructor for the player class.
* @param The player's name.
*/
Player(string name);
/*
* This is a mutator method, it sets the player's number.
* @param The player's number.
*/
void setNumber(int number);
/*
* Add comments for this method in your inherited class.
*/
virtualvoid setMinutesPlayed(int minutes) = 0; // Question 6 - why does this method equal zero?
/*
* This is a method to print out a players stats, its virtual,
* so it is possible to override it.
*/
virtualvoid printStats() const; // Question 7 - What does 'const' do here?
};
#endif
/*
* This is the implementation file for the player class for CSC 4111 Lab 1 Task 2
* You are not allowed to change this file.
* 10 points will be subtracted if this file is modified.
*
* @Author C. Dorman
*/
#include "player.h"
/*
* This is the constructor for the player class.
* @param The player's name.
*/
Player::Player(string name){
this->name = name;
}
/*
* This is a mutator method, it sets the player's number.
* @param The player's number.
*/
void Player::setNumber(int number){
this->number = number;
}
/*
* This is a method to print out a players stats, its virtual,
* so it is possible to override it.
*/
void Player::printStats() const{
cout << "Name: " << name << "\tNumber: " << number;
}
//offense.h
#ifndef OFFENSE_H
#define OFFENSE_H
#include "player.h"
#include <iostream>
usingnamespace std;
class Offense : public Player{
public:
//offensive class constructor. Calling base constructor.
Offense(string name);
//using pure virtual method. The virtual method is a method whose behavior can be overridden within an inheriting class by a function with the
//same signiture.
virtualvoid setMinutesPlayed(int minutes);
void setYards(int yards);
virtualvoid printStats() const;
private:
//number of yards player had
int yards;
};
#endif