मेरे पास टेक्स्ट त्वरित सी ++ से निम्न स्रोत है। जब मैं स्रोत फ़ाइल संकलित करने का प्रयास करता हूं तो मुझे नीचे सूचीबद्ध निम्न संकलन त्रुटि मिलती है। मैं सी ++ भाषा का नौसिखिया हूं इसलिए आपकी सहायता की सराहना की जाएगी।टाइप ड्रॉप के मूल्य के संदर्भ के बाध्यकारी क्वालीफायर
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
#include <stdexcept>
using namespace std;
struct Student_info {
string name;
double midterm, final;
vector<double> homework;
};
double median(vector<double>);
double grade(const Student_info&);
double grade(double, double, double);
double grade(double, double, const vector<double>&);
istream& read_hw(istream&, vector<double>&);
istream& read(istream&, Student_info&);
bool compare(const Student_info&, Student_info&);
int main() {
vector<Student_info> students;
Student_info record;
string::size_type maxlen = 0;
while(read(cin, record)) {
maxlen = max(maxlen, record.name.size());
students.push_back(record);
}
sort(students.begin(), students.end(), compare);
for(vector<Student_info>::size_type i = 0;
i != students.size(); ++i) {
cout << students[i].name << string(maxlen + 1 - students[i].name.size(), ' ');
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;
}
return 0;
}
double median(vector<double> vec) {
typedef vector<double>::size_type vec_sz;
vec_sz size = vec.size();
if(size == 0)
throw domain_error("median of an empty vector");
sort(vec.begin(), vec.end());
vec_sz mid = size/2;
return size%2 == 0 ? (vec[mid] + vec[mid - 1])/2 : vec[mid];
}
double grade(const Student_info& s) {
return grade(s.midterm, s.final, s.homework);
}
double grade(double midterm, double final, double homework) {
return 0.2*midterm + 0.4*final + 0.4*homework;
}
double grade(double midterm, double final, const vector<double>& hw) {
if(hw.size() == 0)
throw domain_error("student has done no homework");
return grade(midterm, final, median(hw));
}
istream& read_hw(istream& in, vector<double>& hw) {
if(in) {
hw.clear();
double x;
while(in >> x)
hw.push_back(x);
in.clear();
}
return in;
}
istream& read(istream& is, Student_info& s) {
is >> s.name >> s.midterm >> s.final;
read_hw(is, s.homework);
return is;
}
bool compare(const Student_info& x, const Student_info& y) {
return x.name < y.name;
}
संदर्भ के बंधन प्रकार 'स्थिरांक Student_info' के एक मूल्य के लिए टाइप करने के लिए 'Student_info' क्वालिफायर चला जाता है compute_grades_rev-ख
लाइन 125, बाहरी स्थान: /usr/include/c++/4.2.1/bits/
template<typename _Tp, typename _Compare>
inline const _Tp&
__median(const _Tp& __a, const _Tp& __b, const _Tp& __c, _Compare __comp)
{
// concept requirements
__glibcxx_function_requires(_BinaryFunctionConcept<_Compare,bool,_Tp,_Tp>)
if (__comp(__a, __b))
if (__comp(__b, __c))
return __b;
else if (__comp(__a, __c))
return __c;
else
return __a;
else if (__comp(__a, __c))
return __a;
else if (__comp(__b, __c))
return __c;
else
return __b;
}
मैं से तुलना समारोह की घोषणा बदलने के लिए: stl_algo.h C/C++ समस्या
यहाँ stl_algo.h से कोड है
bool compare(const Student_info&, Student_info&);
bool compare(const Student_info, Student_info);
अब यह संकलित करता है।
कौन सा लाइन 125 है? – user3553031
@ user3553031 अगर (__comp (__ a, __b)) – dcrearer