One error

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * 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>
using namespace 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");

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//defense.h

#ifndef DEFENSE_H
#define DEFENSE_H
#include<iostream>
#include "player.h"

using namespace std;

class Defense : public Player 
{
public:
	Defense(string name);

	virtual void setMinutesPlayed(int minutes);

	void setTackles(int tackles);

	virtual void printStats() const;

private:
	int tackles;
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//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;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * 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>

using namespace 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.
	 */
	virtual void 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.
	 */
	virtual void printStats() const; // Question 7 - What does 'const' do here? 
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * 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;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//offense.h
#ifndef OFFENSE_H
#define OFFENSE_H

#include "player.h"
#include <iostream>

using namespace 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.

	virtual void setMinutesPlayed(int minutes);

	void setYards(int yards);

	virtual void printStats() const;

private:

	//number of yards player had

	int yards;
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//offense.cpp
#include "offense.h"

//constructor for the offensive class. calling base constructor.

Offense::Offense(string name) : Player (name)
{}

void Offense::setMinutesPlayed(int minutes)
{
	this->minutes=minutes;
}

void Offense::setYards(int yards)
{
	this->yards=yards;
}

void Offense::printStats() const
{
	Player::printStats();
	cout<<"\tMinutes: "<<minutes<<"\tYards: "<<yards<<endl;
}
i know you added this comment in your cpp :

//Making the constructor for the defensive class.
//Calls the base constructor.

But you still have to write a constructor for Defense (like you've done in Offense actually) as you've declared it in your header file:
 
Defense(string name);


Last edited on
Wow. I can't believe I missed that. Thank you so much. I really appreciate it :)
Topic archived. No new replies allowed.