Help with errors

So i am doing a program using classes. Namely a Student class, and i have it all done. When i try to run it i get an error LNK2019 and error LNK1120 (i am only getting one instance of the errors, so i figure its only one problem). I have spent the last hour or so looking around the internet and i can't seem to find anything to help me with my problem.

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

//student Class declaration
class Student
{
	private:
		string name;
		int id;
		int *test;
		int num;
		void makeArray();
	public:
		Student();
		Student(int n);
		Student(string nm, int i, int n);
		void setName(string nm);
		void setID(int i);
		void setScore(int i, int s);
		string getName() const;
		int getID() const;
		void showScore();
		void display();
		~Student();			
};

//makeArray allocate an int array with num elements, 
//assigns the address of the array to test and assigns 0 to all elements
void Student::makeArray()
{
	int size = Student::num;
	int *studentArray;
	studentArray = new int[num];
	Student::test = studentArray;

	test = 0;
}

//Student function
Student::Student()
{
	setName("NONE");
	setID(10);
	Student::num = 3;


}

//Second student function, takes in 2 parameters
Student::Student(int n)
{
	setName("None");
	setID(10);
	if(n > 0){
		Student::num = n;
	}else{
		Student::num = 3;
	}
	makeArray();
}

//Third student function, takes in 3 parameters
Student::Student(string nm, int i, int n)
{
	setName(nm);
	setID(i);
	if(n > 0){
		Student::num = n;
	}else{
		Student::num = 3;
	}
	makeArray();
}

//sets name to nm
void Student::setName(string nm)
{
	Student::name = nm;
}

//sets id to i. If i is in range of 10 - 99. If not then it sets id to 10 and prits and error
//message saying it cannot set the id to i. The error message should include the students name
//by displaying the return value of get name
void Student::setID(int i)
{
	if(i >= 10 && i <= 99){
		Student::id = i;
	}else{
		Student::id = 10;
		cout << "Invalid.  Can not set id to " << i << " for " << getName() << endl;
	}
}

//only sets the score if index i is a valid index within the bounds of the dynamic array holding the test scores,
//and if s is a valid score in teh range of 0-100. If it doesn't meet thse conditions, an error message should display
// saying the test i cantnot be set to s. Error message should include student's name by displaying return value or getName.
void Student::setScore(int i, int s)
{
	if(i < Student::num){
		if(s >= 0 && s <= 100){
			test[i] = s;
		}else{
			cout << "Invalid.  Can not set test " << i << " to " << s << " for " << getName() << endl;
		}
	}else{
		cout << "Invalid.  Can not set test " << i << " to " << s << " for " << getName() << endl;
	}
}

//returns the name
string Student::getName() const
{
	return Student::name;
}

//returns the id
int Student::getID() const
{
	return Student::id;
}

//displays the test number and the score
void Student::showScore()
{
	for(int count = 0; count < Student::num; count++)
	{
		cout << "Test " << count << "had a score of " << test[count] << endl;
	}
}

//get and display the student's information
void Student::display()
{
	cout << "The Name: " << getName();
	cout << "The ID: " << getID();
	showScore();
	cout << endl;
	cout << endl;
}

//frees the array that test is pointing to
Student::~Student()
{
	free(test);
}
int main()
{
	//sets up the 3 students
	Student a;
	Student b(4);
	Student c("Joe", 40, 5);

	//calls the set functions
	cout << "Calling the set functions";
	//for student a
	a.setName("Tom");
	a.setID(200);
	a.setID(20);
	a.setScore(0, 75);
	a.setScore(1, 85);
	a.setScore(2, 95);

	//for student b
	b.setName("John");
	b.setID(30);
	b.setScore(0, 70);
	b.setScore(1, 80);
	b.setScore(2, 90);
	b.setScore(3, 100);

	//for student c
	c.setScore(0, 90);
	c.setScore(1, 91);
	c.setScore(2, 92);
	c.setScore(3, 93);
	c.setScore(4, 94);
	c.setScore(5, 95);
	c.setScore(4, 105);
	c.setScore(5, 105);

	//the display function
	a.display();
	b.display();
	c.display();

	
	system("pause");
	return 0;
}


any help to trace the error and even point me in the right direction to fix my own problem would be great. I've asked some friends and they don't know enough about C++ to be of any help.

Thanks in advance.


This is the full text from the 2 errors
error LNK2019: unresolved external symbol "class Student __cdecl a(void)" (?a@@YA?AVStudent@@XZ) referenced in function _main error LNK1120: 1 unresolved externals


EDIT: code now reflects most recent updates
Last edited on
Hey ferigs911, i would love to help you with your problem.
Could you post the full text of the linker error?
I can help with errors! How many errors do you need? I can add any number of errors to your code!:)
Thumper, i edited the original post to have the full text of the 2 errors at the bottom
This

Student a();
is a function declaration with name a that has no parameters and returns an object of type Student.

So a is not an object of type Student as you think.

As the result the following code

1
2
3
4
5
	a().setName("Tom");
	a().setID(200);
	a().setScore(0, 75);
	a().setScore(1, 85);
	a().setScore(2, 95);

is invalid. There is no definition of the function with name a,
ok thanks for the help, BUT i fixed that and now i have some kind of a run time error that just crashes the program before it can do anything. it Highlights line 109

test[i] = s;
In means that i is outside the acceptable range of indexes for test.
how would i go about fixing that problem?

i figure i have to make it so "i" is in the acceptable range but where would i make that happen?


EDIT:
just ran it again and now lines 38, 92, 105, 108, 129, 138-140, 156-160, and 183 have these lime green colored blocks next to them and the error opens this crtexe.cpp file and highlights line number 555 in there:

mainret = main(argc, argv, envp);

this is by far the most error filled program i have ever done. I really need help i cant figure out what it means or wants me to do
Last edited on
You may not call main in C++.
What do you mean i can't call main in C++ that is how i always have been doing it.
Topic archived. No new replies allowed.