crazy C++ compiler error messages about a copy constructor from MinGW32 -
i'm beginning c++ student , i'm using jgrasp , have installed mingw32 because turn our assignments remotely linux machine helps ensure it'll work simulating linux environment in windows or something. mingw32 installed "base package" , manually selected c++ compiler option. in jgrasp went settings>>path/classpath>>workspace
, added new path directory c:\mingw\mingw32\bin
it'll know g++ compiler is.
i these crazy error messages upon compiling in jgrasp can't make sense of. think has header because of iostream.
#include <string.h> #include <iostream> #include <iomanip> #include <fstream> using namespace std;
here compiler error messages:
ios:42:0, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, lab1.cpp:6: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h: in copy constructor 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)': ios_base.h:786:5: error: 'std::ios_base::ios_base(const std::ios_base&)' private ios_base(const ios_base&); ^ ios:44:0, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, lab1.cpp:6: basic_ios.h:66:11: error: within context class basic_ios : public ios_base ^ in file included lab1.cpp:8:0: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream: in copy constructor 'std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)': fstream:427:11: note: synthesized method 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' first required here class basic_ifstream : public basic_istream<_chart, _traits> ^ ios:43:0, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, lab1.cpp:6: c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\streambuf: in copy constructor 'std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)': streambuf:802:7: error: 'std::basic_streambuf<_chart, _traits>::basic_streambuf(const std::basic_streambuf<_chart, _traits>&) [with _chart = char; _traits = std::char_traits<char>]' private basic_streambuf(const basic_streambuf& __sb) ^ in file included lab1.cpp:8:0: fstream:72:11: error: within context class basic_filebuf : public basic_streambuf<_chart, _traits> ^ c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream: in copy constructor 'std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)': fstream:427:11: note: synthesized method 'std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)' first required here class basic_ifstream : public basic_istream<_chart, _traits>
and here code far:
// ---------------------------------------------------------------------------- // write meaningful doxygen comments , assumptions #include <string.h> #include <iostream> #include <iomanip> #include <fstream> using namespace std; int const maxsize = 100; // maximum number of records in total int const maxlength = 31; // maximum string length int const maxgrade = 100; // highest possible grade int const lowgrade = 0; // lowest possible grade int const group = 10; // group amount int const histogramsize = (maxgrade-lowgrade)/group + 1; // grouped group struct studenttype { // information of 1 student int grade; // grade of student char last[maxlength]; // last name (maxlength-1 @ most) char first[maxlength]; // first name (maxlength-1 @ most) }; // prototypes go here bool sortinput(ifstream, studenttype, int); void displaylist(studenttype, int); /*sethistrogram(); displayhistogram(); findaverage();*/ //------------------------------- main ---------------------------------------- int main() { studenttype students[maxsize]; // list of maxsize number of students int size = 0; // total number of students int histogram[histogramsize]; // grades grouped group int average = 0; // average exam score, truncated // creates file object , opens data file ifstream infile("data1.txt"); if (!infile) { cout << "file not opened." << endl; return 1; } // read , sort input last first name bool successfulread = sortinput(infile, students, size); // display list, histogram, , class average if (successfulread) { displaylist(students[], size); // sethistogram(... figure parameters ...); // displayhistogram(... figure parameters ...); // average = findaverage(... figure parameters ...); cout << "average grade: " << average << endl << endl; } return 0; } bool sortinput(ifstream infile, studenttype students[], int size) { while(infile) { studenttype temp; infile >> temp.last >> temp.first >> temp.grade; //for(int = maxsize-1; > maxsize-1-size; i--) for(int = size; > 0; i--) { if(strcmp(temp.last, students[i].last) < 0) { //copy current name , grade down //strcopy(students[i+1].last, students[i].last); students[i+1] = students[i]; } else if(strcmp(temp.last, students[i].last) == 0 && strcmp(temp.first, students[i].first) < 0)) { //copy/assign current name , grade down students[i+1] = students[i]; } else { //found right place, break out of loop break; } } //now you've made room, insert (copy) new name correct sorted position students[i] = temp; } return true; } void displaylist(studenttype students[], int size) { cout << "list of names sorted:" << end1; for(int = 0; < size; i++) { cout << " " << student[i].grade << " " << students[].last << " " << students[i].first << end1; } } // ---------------------------------------------------------------------------- // functions meaningful doxygen comments , assumptions go here
i ran myself. problem sortinput
takes ifstream
value, instead of reference. ifstream
s don't copied. change declaration to:
bool sortinput(ifstream&, studenttype, int);
note &
Comments
Post a Comment