LNK2019 error that I can't figure out how to resolve

In my program, I am trying to create a program that places randomly generated integers in to a vector and then bubble sorts them. When I try to build the file I get the following error:

"Error LNK2019 unresolved external symbol "private: class std::vector<int,class std::allocator<int> > __thiscall SortedVector::listOfNums(unsigned int)" (?listOfNums@SortedVector@@AAE?AV?$vector@HV?$allocator@H@std@@@std@@I@Z) referenced in function "public: void __thiscall SortedVector::bubbleSortVector(void)" (?bubbleSortVector@SortedVector@@QAEXXZ) Test1 C:\Users\Darien\Documents\C++ files\Test1\Test1\main.obj"

Does anyone know what external symbol is causing this problem? I don't have any user created header files.

Here is my code:

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
  
#include "pch.h"
#include <iostream>
#include <vector>
#include <ctime>

class SortedVector
{
	
	public:

		SortedVector(size_t vectorSize = 100)
			: listOfNums(vectorSize) { };

		void placeRandNumsInVector() {
			for (unsigned int i = 0; i < listOfNums.size(); i++) {

				int randomNumber = rand() % 1000 + 1;

				listOfNums[i] = randomNumber;

				std::cout << listOfNums[i] << " ";
			}
		}

		void bubbleSortVector() {
			bool whileLoopEnd = false;

			while (whileLoopEnd == false) {

				bool forLoopEnd = true;

				for (unsigned int i = 0; i < listOfNums.size(); i++) {

					//if loop is on final iteration, then listOfNums does not compare its elements to each other
					if (i != (listOfNums.size() - 1)) {
						if (listOfNums[i] > listOfNums[i + 1]) {
							//listOfNums[i] and listOfNums[i + 1] swap values
							int tempVar = listOfNums[i + 1];
							listOfNums[i + 1] = listOfNums[i];
							listOfNums[i] = tempVar;
							forLoopEnd = false;
						}
					}
					//if no values were swapped, then while loop ends and sorting ends
					else if (i == (listOfNums.size() - 1)) {
						if (forLoopEnd == true) {
							whileLoopEnd = true;
						}
					}

				}
			}
		}

		void printVectorValues() {
			for (unsigned int i = 0; i < listOfNums.size(); i++) {
				std::cout << listOfNums[i] << " ";
			}
		}

    private:
		std::vector<int> listOfNums;
};

int main()
{
	//determines seed based on the time of program execution
	srand( (unsigned int)time(NULL));

	//instantiates instance of SortedArray
	SortedVector sortedVector;

	std::cout << "initial unsorted array values: ";

	////for loop assigns each vector location a random integer
	sortedVector.placeRandNumsInVector();

	std::cout << std::endl;
	std::cout << "Integers are now placed in array" << std::endl;
	std::cout << std::endl;

	std::cout << "Program will now sort integers in listOfNums from least to greatest" << std::endl;
	std::cout << std::endl;

	//Sorts integers in listOfNums from least to greatest
	sortedVector.bubbleSortVector();

	std::cout << "Sorted vector: ";
	
	sortedVector.printVectorValues();
	
	return 0;

};
Last edited on
Try doing a clean build.

Less "pch.h", your code links as-is using both GCC and Clang:
http://coliru.stacked-crooked.com/a/806993f89b6d4278
Last edited on
What's in pch.h?
When I get rid of "pch.h" I get this error message:
"Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source?"

I should have added I am using Visual Studio IDE. I suppose I can also just compile and run it in Power Shell as well.
Who told you to get rid of it?
The question is, what is in it?
Post its contents.
pch.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file

#ifndef PCH_H
#define PCH_H

// TODO: add headers that you want to pre-compile here

#endif //PCH_H 
So there's nothing in it, really.
Then there's nothing wrong with your program and the error makes no sense relating to the code you've shown.
In fact, it seems to be related to your previous question (and therefore previous code).

Did you do a "clean build" as suggested?

Last edited on
If you remove pch.h then you need to set Pre-compiled header to "Not Using Precompiled Headers" under C++->Precompiled headers
Topic archived. No new replies allowed.