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.
#include <iostream>
#include <new>
#include "student.h"
usingnamespace 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";
}
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.