Alright, while doing work at home, I use GCC with TextPad for whatever coding assignments II have. While at school, I have the "luxury" of using metrowerks codewarrior 4 and/or GCC. To keep consistency, I use GCC.Textpad at school too.
Here's where a couple of weird problem arise :
This code compiles and runs perfectly under Metrowerks with no errors. However, under GCC/GDB , I get several errors, which to my studnet mind, do not seem to aid my debugging processes to find the error in why GCC does not work on this code, yet Metrowerks does.
THis pertains to issues with GCC, not with my code... hopefully.
What is the difference within Metrowerks and GCC (I know, probably a world of differences, but this is.. queer) that would cause these problems to arise?
Here's where a couple of weird problem arise :
code:<HR>Code:#include <iostream> #include <fstream> #include <string> #include <algorithm> using namespace std; class OutRecord { public : string first, last; float gpa; bool operator<(const OutRecord& x) { return gpa < x.gpa; } }; float GradeReturn(char input, char input2); int main (void) { ifstream in("mayers.in"); ofstream out("mayers.out"); int s; in >> s; OutRecord studs[1000]; for (int i=0;i<s;i++) { int loop=0; float junk=0; float credits=0; float tempcreds=0; float tempgrade=0; in >> studs[i].first >> studs[i].last >> loop; for (int j=0;j<loop;j++) { int credits; string lgrade; string dummy; in >> dummy >> credits >> lgrade; if(lgrade.length()==2) { junk=GradeReturn(lgrade[0], lgrade[1]); } else { junk=GradeReturn(lgrade[0], 'J'); } tempcreds+=credits; tempgrade+=(credits*junk); } studs[i].gpa=(tempgrade/tempcreds); } sort(studs, studs+s); for(--s;s>=0;s--) { out << studs[s].last << " " << studs[s].first << " " << studs[s].gpa << endl; } return 0; } float GradeReturn(char input, char input2) { float returnval=0; switch(input) { case 'A' : returnval=4; break; case 'B' : returnval=3; break; case 'C' : returnval=2; break; case 'D' : returnval=1; break; default : return 0; break; } switch(input2) { case '+' : returnval+=.3; break; case '-' : returnval-=.3; break; default : returnval+=0; break; } return returnval; }
This code compiles and runs perfectly under Metrowerks with no errors. However, under GCC/GDB , I get several errors, which to my studnet mind, do not seem to aid my debugging processes to find the error in why GCC does not work on this code, yet Metrowerks does.
THis pertains to issues with GCC, not with my code... hopefully.
code:<HR>Code:c:/djgpp/lang/cxx-v3/bits/stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = OutRecord]': c:/djgpp/lang/cxx-v3/bits/stl_algo.h:1634: instantiated from `void std::__introsort_loop(_RandomAccessIter, _RandomAccessIter, _Tp*, _Size) [with _RandomAccessIter = OutRecord*, _Tp = OutRecord, _Size = int]' c:/djgpp/lang/cxx-v3/bits/stl_algo.h:1672: instantiated from `void std::sort(_RandomAccessIter, _RandomAccessIter) [with _RandomAccessIter = OutRecord*]' Z:/code/junk/mayers.cpp:66: instantiated from here c:/djgpp/lang/cxx-v3/bits/stl_algo.h:77: passing `const OutRecord' as `this' argument of `bool OutRecord::operator<(const OutRecord&)' discards qualifiers c:/djgpp/lang/cxx-v3/bits/stl_algo.h:78: passing `const OutRecord' as `this' argument of `bool OutRecord::operator<(const OutRecord&)' discards qualifiers c:/djgpp/lang/cxx-v3/bits/stl_algo.h:80: passing `const OutRecord' as `this' argument of `bool OutRecord::operator<(const OutRecord&)' discards qualifiers c:/djgpp/lang/cxx-v3/bits/stl_algo.h:84: passing `const OutRecord' as `this' argument of `bool OutRecord::operator<(const OutRecord&)' discards qualifiers c:/djgpp/lang/cxx-v3/bits/stl_algo.h:86: passing `const OutRecord' as `this' argument of `bool OutRecord::operator<(const OutRecord&)' discards qualifiers
What is the difference within Metrowerks and GCC (I know, probably a world of differences, but this is.. queer) that would cause these problems to arise?