error LNK2019

hey, i keep running into an error problem... What could be causing this?

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

//bow.h
#include <iostream>
#include <string>

using std::string;



class Bow
{
	
	// data member declarations
	string colour;
	bool drawn;
	int numOfArrows;
public:
	 //constructor
	Bow(string aColour);
 // destructor
 Bow::~Bow();
	// methods
	void draw();
	int fire();

};


//bow.cpp

#include <iostream>
#include <cstring>
#include "bow.h"

class ArcheryCompetition
{
private:
	//memeber variables
	int rounds;
	float redScore;
	Bow red;
	float blueScore;
	Bow blue;
public:
	//constructor
	ArcheryCompetition(int lrounds);

	//destructor
	~ArcheryCompetition();

	//methods
	int compete(void);
};

//constructs an ArcheryCompetition object

ArcheryCompetition::ArcheryCompetition(int lrounds) :
	rounds(lrounds), red(Bow("red")),
		blue(Bow("blue")), redScore(0), blueScore(0)
	{ }

	//the destructor

ArcheryCompetition::~ArcheryCompetition()
{
}

//the heart of the game
//walks the player through an entire competition
//and figures out who won
int ArcheryCompetition::compete()
{
	using std::cout;
	//go through each round, keeping track of the score
	for(int i = 0; i < rounds; i++)
	{
		cout << "now on round " << i+1 << ".\n";
		red.draw();
		blue.draw();
		redScore = (red.fire() + redScore * i)/(i+1) ;
		blueScore = (blue.fire() + redScore * i)/(i+1) ;
	}
	//figure out who won
	if(redScore == blueScore)
		cout << "We have a tie!!!\n";
	else if(redScore < blueScore)
		cout <<"Blue wins her hand!!\n";
	else 
		cout << "red wins her hand!!\n";
	return 1;
}

int main(void)
{
	//the driver function: constructs the object and calls the appropriate methods
	ArcheryCompetition plymouthSquare(2);
	plymouthSquare.compete();
	return 0;
}



the error is shown as:

1>bow.obj : error LNK2019: unresolved external symbol "public: __thiscall Bow::~Bow(void)" (??1Bow@@QAE@XZ) referenced in function "public: __thiscall ArcheryCompetition::ArcheryCompetition(int)" (??0ArcheryCompetition@@QAE@H@Z)

1>bow.obj : error LNK2019: unresolved external symbol "public: __thiscall Bow::Bow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Bow@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall ArcheryCompetition::ArcheryCompetition(int)" (??0ArcheryCompetition@@QAE@H@Z)

1>bow.obj : error LNK2019: unresolved external symbol "public: int __thiscall Bow::fire(void)" (?fire@Bow@@QAEHXZ) referenced in function "public: int __thiscall ArcheryCompetition::compete(void)" (?compete@ArcheryCompetition@@QAEHXZ)

1>bow.obj : error LNK2019: unresolved external symbol "public: void __thiscall Bow::draw(void)" (?draw@Bow@@QAEXXZ) referenced in function "public: int __thiscall ArcheryCompetition::compete(void)" (?compete@ArcheryCompetition@@QAEHXZ)

1>c:\users\blahblah\documents\visual studio 2010\Projects\test\Debug\test.exe : fatal error LNK1120: 4 unresolved externals

thanks in advanced
What could be causing this?
Nothing from class Bow is implemented. It's supposed to be in bow.cpp, but isn't apparently
ahh okay, is there any reason why nothing from class bow is being implemented, have i missed something?
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//bow.h
#include <iostream>
#include <string>

using std::string;



class Bow
{
	
	// data member declarations
	string colour;
	bool drawn;
	int numOfArrows;
public:
	 //constructor
	Bow(string aColour);
 // destructor
 Bow::~Bow();
	// methods
	void draw();
	int fire();

};


//bow.cpp

#include <iostream>
#include <cstring>
#include "bow.h"

class ArcheryCompetition
{
private:
	//memeber variables
	int rounds;
	float redScore;
	Bow red;
	float blueScore;
	Bow blue;
public:
	//constructor
	ArcheryCompetition(int lrounds);

	//destructor
	~ArcheryCompetition();

	//methods
	int compete(void);
};

//constructs an ArcheryCompetition object

ArcheryCompetition::ArcheryCompetition(int lrounds) :
	rounds(lrounds), red(Bow("red")),
		blue(Bow("blue")), redScore(0), blueScore(0)
	{ }

	//the destructor

ArcheryCompetition::~ArcheryCompetition()
{
}

//the heart of the game
//walks the player through an entire competition
//and figures out who won
int ArcheryCompetition::compete()
{
	using std::cout;
	//go through each round, keeping track of the score
	for(int i = 0; i < rounds; i++)
	{
		cout << "now on round " << i+1 << ".\n";
		red.draw();
		blue.draw();
		redScore = (red.fire() + redScore * i)/(i+1) ;
		blueScore = (blue.fire() + redScore * i)/(i+1) ;
	}
	//figure out who won
	if(redScore == blueScore)
		cout << "We have a tie!!!\n";
	else if(redScore < blueScore)
		cout <<"Blue wins her hand!!\n";
	else 
		cout << "red wins her hand!!\n";
	return 1;
}

int main(void)
{
	//the driver function: constructs the object and calls the appropriate methods
	ArcheryCompetition plymouthSquare(2);
	plymouthSquare.compete();
	return 0;
}


Line 21: Remove Bow::-part This is not used inside a Bow-class definition itself.

How actually you use your bow-class? i mean... where you define all methods for that class? I mean where is your implementations of these?
1
2
3
4
Bow::Bow(string aColour);
Bow::~Bow();
void Bow::draw();
int Bow::fire();



Adding more as/if i find them

Rule of thumb: create class "prototype" in the header file (.h) and the implementation in source file (.cpp). DO NOT implement another classes in other classes source file :)
Last edited on
Your code is supposed to look something along this:
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//bow.h
#include <iostream>
#include <string>

using std::string;



class Bow
{
	
	// data member declarations
	string colour;
	bool drawn;
	int numOfArrows;
public:
	 //constructor
	Bow(string aColour);
 // destructor
 Bow::~Bow();
	// methods
	void draw();
	int fire();

};


//bow.cpp

Bow::Bow(string aColour)
{
... // Your implementation
}

// destructor
Bow::~Bow()
{
 // Your implementation
}

// methods
void Bow::draw()
{
... // Your implementation
}

int Bow::fire()
{
... // Your implementation
}


// ArcheryCompetition.h

#include <iostream>
#include <cstring>
#include "bow.h"

class ArcheryCompetition
{
private:
	//memeber variables
	int rounds;
	float redScore;
	Bow red;
	float blueScore;
	Bow blue;
public:
	//constructor
	ArcheryCompetition(int lrounds);

	//destructor
	~ArcheryCompetition();

	//methods
	int compete(void);
};

// ArcheryCompetition.cpp

//constructs an ArcheryCompetition object

ArcheryCompetition::ArcheryCompetition(int lrounds) :
	rounds(lrounds), red(Bow("red")),
		blue(Bow("blue")), redScore(0), blueScore(0)
	{ }

	//the destructor

ArcheryCompetition::~ArcheryCompetition()
{
}

//the heart of the game
//walks the player through an entire competition
//and figures out who won
int ArcheryCompetition::compete()
{
	using std::cout;
	//go through each round, keeping track of the score
	for(int i = 0; i < rounds; i++)
	{
		cout << "now on round " << i+1 << ".\n";
		red.draw();
		blue.draw();
		redScore = (red.fire() + redScore * i)/(i+1) ;
		blueScore = (blue.fire() + redScore * i)/(i+1) ;
	}
	//figure out who won
	if(redScore == blueScore)
		cout << "We have a tie!!!\n";
	else if(redScore < blueScore)
		cout <<"Blue wins her hand!!\n";
	else 
		cout << "red wins her hand!!\n";
	return 1;
}

// main.cpp

int main(void)
{
	//the driver function: constructs the object and calls the appropriate methods
	ArcheryCompetition plymouthSquare(2);
	plymouthSquare.compete();
	return 0;
}
Topic archived. No new replies allowed.