Unresolved externals;

These are the errors I am getting:
Error 3 error LNK2019: unresolved external symbol "public: __thiscall StudentTestScores::StudentTestScores(void)" (??0StudentTestScores@@QAE@XZ) referenced in function _main c:\Users\cohena2\documents\visual studio 2010\Projects\6\6\NewLab6 Main.obj

Error 4 error LNK1120: 1 unresolved externals c:\users\cohena2\documents\visual studio 2010\Projects\6\Debug\6.exe 1

This is my class declaration:
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

class StudentTestScores;
const double NA= 0;



class StudentTestScores
{
	private:
		string studentName;
		double *testScores;
		int numTestScores;
		char LetterGrade;
		void createTestScoresArray(int size)
		{
			numTestScores=size;
			testScores=new double[size];
			for (int i=0; i<size; i++)
			{	
				testScores[i]=NA;
			}
		}
    public:
		// class constructor
		StudentTestScores();
		StudentTestScores(string name, int numScores ) 
		{ 
			studentName=name;
			createTestScoresArray(numScores);
		}

		// class copy constructor
		StudentTestScores(const StudentTestScores &other) 
		{
			studentName = other.studentName;
			numTestScores = other.numTestScores;
			testScores = new double[numTestScores];
			for (int i = 0; i < numTestScores; i++)
			{
				testScores[i] = other.testScores[i];
			}
		}
		
		// class destructor
		~StudentTestScores()
		{	delete [] testScores;}
	
		// accessors & mutators 
		void setLetterGrade(char x)
		{ LetterGrade=x;}

		char getLetterGrade()
		{ return LetterGrade;}

		void setName(string x)
		{	studentName=x;}
	
		string getName() const
		{	return studentName;}
		
		void setTestScore(double score, int index)
		{	testScores[index] = score;}

		double getTestScore(int index)const
		{	return testScores[index];}

		void setNumTestScores(int x)
		{ numTestScores=x;}
	
		int getNumTestScores() const
		{	return numTestScores;}
				
		//Assignment operator overload
		void operator=(const StudentTestScores &other)
		{
			delete [] testScores;
			studentName = other.studentName;
			numTestScores =other.numTestScores;
			testScores = new double[numTestScores];
			for(int i = 0; i < numTestScores; i++)
			{
				testScores[i] = other.testScores[i];
			}

		}
		
		friend ostream& operator <<(ostream &, StudentTestScores &);
		friend istream& operator >>(istream &, StudentTestScores &);

		friend ifstream& operator >>(ifstream &, StudentTestScores &);
		
		//displayInfo prototype
		void displayInfo(StudentTestScores);

};

//Overload the Stream I/O operators. 
ostream& operator <<(ostream &os, StudentTestScores &x)
	{	
			os<< x.getName() << "\t" << x.getNumTestScores() << "\t" << x.getLetterGrade()<<"\t";

		
	for (int i = 0; i < x.getNumTestScores(); i++)
	{
			os<< x.getTestScore(i)<<", ";
	}
	cout<<".\n";
		return os;
	}

istream& operator >>(istream &is, StudentTestScores &object)
	{
		cin.get();
		cout<<"Enter student name : ";	
		
		getline(is,object.studentName);
		
	
		cout<<"Enter number of test scores : ";
		is>>object.numTestScores;
		
		object.testScores=new double[object.numTestScores];
				
		for(int i=0; i<object.numTestScores;i++)
		{
			
			cout<<"Enter score for test"<<(i+1)<<" : ";
			is>>object.testScores[i];
		
		}

		return is;
	}

ifstream& operator >>(ifstream &file, StudentTestScores &obj)
{
    int numTestScores=0;
	float sum=0;
	string Name;
	
	getline(file, Name, '\t');
	file>>numTestScores;
	
	StudentTestScores(Name, numTestScores);
	
	for(int i=0; i<obj.numTestScores;i++)
		{
			file>>obj.testScores[i];
			sum=sum+obj.testScores[i];		
		}

	if (sum>=90 && sum<=100)
		obj.setLetterGrade('A');
	else if (sum>=80 && sum<=89)
		obj.setLetterGrade('B');
	else if (sum>=70 && sum<=79)
		obj.setLetterGrade('C');
	else if (sum<=69&& sum>=0)
		obj.setLetterGrade('D');
	else
		obj.setLetterGrade('N');

	return file;

}



#endif 


This is my client code. The real error occurs on line 26.

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
#include "STUDENTTESTSCORES 5.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

void showContent(fstream&);

int main()
{	
	StudentTestScores *ptr;
	
	fstream file;
	int numOfStudents;
		
	file.open("C:\\Users\\cohena2\\Desktop\\tests.txt", ios::app || ios::in);
	
	if(!file)
	{ cout<<"file not found\n";}
	else if (file) 
	{cout<<"File found \n";}
			
	file>>numOfStudents;
	cout<<numOfStudents;

	ptr=new StudentTestScores[numOfStudents];
	
	for(int i=0; i<numOfStudents;i++)
	{
		file>>ptr[i];
	}

	//output 
	for( int i =0; i < numOfStudents; ++i)
	{ cout << ptr[i] << endl;}		
	
	//showContent(file);
	
	cin.get();cin.get();
	return 0;
}

void showContent(fstream &file)
{
	string line;

	while(getline(file,line))
	{
		cout<<line<<endl;
	}
	
}


Any help would be appreciated, let me know if you have any questions
You're getting a linker error, which most likely means you defined a function 0 times or 2 or more times. All functions need to be defined exactly once.

In this particular case, your linker error is saying that you never defined your default constructor.
I commented out the parameterised constructor and adjusted code for the overloaded operators accordingly.
I am still getting the same error.

Changed 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
 public:
		// class constructor
		StudentTestScores();
		/*StudentTestScores(string name, int numScores ) 
		{ 
			studentName=name;
			createTestScoresArray(numScores);
		}*/
.....

ifstream& operator >>(ifstream &file, StudentTestScores &obj)
{
    int numTestScores=0;
	double sum=0;
	string Name;
	
	getline(file, Name, '\t');
	file>>numTestScores;
	
	//StudentTestScores(Name, numTestScores);
	
	obj.setName(Name);
	obj.setNumTestScores(numTestScores);
	obj.createTestScoresArray(numTestScores);

the rest of the code is the same.

I showed it to the teacher and several other students, no one knows what's going on. They are of no help to me, I need you guys' input please :) thx in advance.
LB wrote:
your default constructor.
dman951753 wrote:
the parameterised constructor
Thx for the help figuring it out, that part of the code now works correctly.
Topic archived. No new replies allowed.