Skip to content

Instantly share code, notes, and snippets.

@ZachMassia
Created July 6, 2012 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZachMassia/3062851 to your computer and use it in GitHub Desktop.
Save ZachMassia/3062851 to your computer and use it in GitHub Desktop.
Sort Error
int ExampleRunner::ex4_2_3()
{
using namespace std;
vector<StudentInfo> students;
StudentInfo record;
string::size_type maxlen = 0;
// Read and store all the records, and find the length of the longets name
while (read(cin, record)) {
maxlen = max(maxlen, record.name.size());
students.push_back(record);
}
// Alphabetize the records
// TODO: fix error with compare, "unresolved overloaded function type"
sort(students.begin(), students.end(), compare);
for (vector<StudentInfo>::size_type i = 0; i != students.size(); ++i) {
// Write the name, padded on the right to maxlen + 1 characters
cout << students[i].name
<< string(maxlen + 1 - students[i].name.size(), ' ');
// Compute and write the grade
try {
double final_grade = grade(students[i]);
streamsize prec = cout.precision();
cout << setprecision(3) << final_grade
<< setprecision(prec);
} catch (domain_error e) {
cout << e.what();
}
cout << endl;
}
// -- End of Method -- //
return 0;
}
bool ExampleRunner::compare(const StudentInfo & x, const StudentInfo & y)
{
return (x.name < y.name);
}
@ZachMassia
Copy link
Author

-------------- Build: Debug in acceleratedC++ ---------------

Compiling: main.cpp
/home/zach/dev/c++/AcceleratedC/main.cpp: In function 'int main()':
/home/zach/dev/c++/AcceleratedC/main.cpp:9:9: warning: unused variable 'exercise' [-Wunused-variable]
Compiling: src/ExampleRunner.cpp
/home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp: In member function 'int ExampleRunner::ex4_2_3()':
/home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp:28:51: error: no matching function for call to 'sort(std::vectorExampleRunner::StudentInfo::iterator, std::vectorExampleRunner::StudentInfo::iterator, )'
/home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp:28:51: note: candidates are:
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/algorithm:63:0,
from /home/zach/dev/c++/AcceleratedC/include/ExampleRunner.h:9,
from /home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_algo.h:5463:5: note: template void std::sort(_RAIter, _RAIter)
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_algo.h:5463:5: note: template argument deduction/substitution failed:
/home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp:28:51: note: candidate expects 2 arguments, 3 provided
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/algorithm:63:0,
from /home/zach/dev/c++/AcceleratedC/include/ExampleRunner.h:9,
from /home/zach/dev/c++/AcceleratedC/src/ExampleRunner.cpp:1:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_algo.h:5499:5: note: void std::sort(_RAIter, _RAIter, _Compare) [with RAIter = __gnu_cxx::__normal_iterator<ExampleRunner::StudentInfo*, std::vectorExampleRunner::StudentInfo >; Compare = bool (ExampleRunner::)(const ExampleRunner::StudentInfo&, const ExampleRunner::StudentInfo&)]
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_algo.h:5499:5: note: no known conversion for argument 3 from '' to 'bool (ExampleRunner::
)(const ExampleRunner::StudentInfo&, const ExampleRunner::StudentInfo&)'
Process terminated with status 1 (0 minutes, 0 seconds)
7 errors, 1 warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment