using dynamic arrays in functions

I have my dynamic array set up with objects of the class student. I need to pass this array to a function so I can sort the students scores in descending order.
I wanted to make sure I am passing the array correctly and have a question about an error i keep getting.
When i try to build this code is gives me an error.
Error code: "error lnk1120: 1 unresolved externals"
The only time I have seen this kind of error before i misspelled by function name but I don't see that here

Lastly, if someone could give me some pointers on how to get the sorting done that would be great. I have only ever sorted integers in an array, never an integer within a class object.


Main Source File
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 <iostream>
#include <new>
#include "student.h"

using namespace std;

void sorting(student *arrayPtr, int);		//pass the array and the array size
//void calcAverage(student *arrayPtr, int);		// pass the array and the array size

int main()
{
	int size,
		index = 0;
	string F,		// for first name
		L;			// for last name
	float SC;		// for score
	int id;			// for student id
	student * arrayPtr;

	cout << "how many students would you like to create? ";
	cin >> size;
	arrayPtr = new student[size];
	
		
		for (int i = 0; i < size; i++)
		{
			cout << "enter first name ";
			cin >> F;
			arrayPtr[i].setFirstName(F);

			cout << endl << "enter last name ";
			cin >> L;
			arrayPtr[i].setLastName(L);

			cout << endl << "enter student id ";
			cin >> id;
			arrayPtr[i].setStudentID(id);

			cout << endl << "enter the score ";
			cin >> SC;
			arrayPtr[i].setScore(SC);
		}
		sorting(arrayPtr, size);
		
		system("pause");
		return 0;
}	

void sorting(student arrayPtr, int size)
{
	cout << "hi";
}


Header File
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
#include <iostream>
#include <string>

using namespace std;

class student
{
public:
	string getFirstName();
	string getLastName();
	int getStudentID();
	float getScore();
	void setStudentID(int);
	void setScore(float);
	void setFirstName(string);
	void setLastName(string);
	string getFullName();
	void printFullName();
	student();
	student(string);
	student(string, string);

private:
	string firstName, lastName;
	int StudentID;
	float score;
};


Implementation File
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
#include <iostream>
#include "student.h"
#include <string>

using namespace std;

string student::getFirstName()
{
	return firstName;
}

string student::getLastName()
{
	return lastName;
}

int student::getStudentID()
{
	return StudentID;
}

float student::getScore()
{
	return score;
}

void student::setStudentID(int ID)
{
	StudentID = ID;
}

void student::setScore(float Score)
{
	score = Score;
}

void student::setFirstName(string fName)
{
	firstName = fName;
}

void student::setLastName(string lName)
{
	lastName = lName;
}

string student::getFullName()
{
	string fullName = firstName + " " + lastName;
	return fullName;
}

void student::printFullName()
{
	cout << firstName << " " << lastName;
}

student::student()
{
	firstName = "";
	lastName = "";
}

student::student(string fName)
{
	firstName = fName;
}

student::student(string fNameIn, string lNameIn)
{
	firstName = fNameIn;
	lastName = lNameIn;
}
Last edited on
Your prototype on line 7 and your implementation on line 49 of the main file don't match (look at the formal parameter lists), so the compiler is complaining that it can't find the implementation for what you've written on line 7.
Thank you, that cleared up my error code.
Topic archived. No new replies allowed.