Can't make out error in function

I'm having trouble trying to figure out why the function displayResults is not resolving. I'm trying to pass a bool value and user input into it. All the functions beforehand weren't giving any errors.

Error code

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "void __cdecl displayResult(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?displayResult@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z) referenced in function _main Project12 C:\Users\trmbe\source\repos\Project12\Source.obj 1


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
#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

vector<string>getVector(const string&);
string getTeam(const string&);
bool search(const string&, vector<string>&);
void displayTeams(vector<string>&);

void displayResults(const string&, bool);

int main()
{
	string teams;
	bool winTeam;
	//int count = 0;
	

	vector<string> winners(getVector("Teams.txt"));
	vector<string> Teams(getVector("Winners.txt"));
	

	teams = getTeam("teams");
	//winners = getTeam("winners");

	displayTeams(winners);
	
	winTeam = search(teams, Teams);
	
	displayResults(teams, winTeam);




	return 0;
}

vector<string>getVector(const string& filename)
{
	ifstream file_obj;
	string teamname;
	vector<string>vec;
	file_obj.open(filename);

	while (file_obj >> teamname)
	{
		vec.push_back(teamname);
	}

	file_obj.close();

	return vec;
}

string getTeam(const string& xteam)
{
	string team;
	cout << "Enter the name of one of the " << xteam << ": ";
	cin >> team;
	return team;
}

bool search(const string& team, vector<string>& vec)
{
	for (int i = 0; i < vec.size(); i++)
	{
		if (vec[i] == team)
			return true;		
	}	
	return false;
}

void displayTeams(vector<string>& vec)
{
	cout << "The following teams have won the World Series once: " << endl;

	for (int i = 0; i < vec.size(); i++)
		cout << vec[i] << endl;

}

void displayResults( string& xteam, bool won)
{
	if (won)
	{
		cout << xteam << " has won the world series " << " times. ";
	}
	else
		cout << "Test";

}
Your error message does not match your current code, because it's saying the issue is 'displayResult', not 'displayResults'.

Your actual error is
:(.text.startup+0x109): undefined reference to `displayResults(std::string const&, bool)'

This is because you define displayResults as void displayResults( string& xteam, bool won) but declare it as void displayResults(const string&, bool);

Prefer the const-parameter version.
Last edited on
Because
void displayResults(const string&, bool);
and
void displayResults( string& xteam, bool won)
don't match.
Last edited on
Oh man thanks I didn't even notice that. I added "const string& xteam" and still getting this error referring to displayResult.


Code Description File Line
LNK2019 unresolved external symbol "void __cdecl displayResult(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (?displayResult@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0_N@Z) referenced in function _main C:\Users\trmbe\source\repos\Project12\Source.obj 1
You also have a prototype for displayResult that needs updating too.
Last edited on
thank you I just noticed I only made the corrections on a copy of the c++ file.
Topic archived. No new replies allowed.