简体   繁体   English

有关来自MinGW32的复制构造函数的疯狂C ++编译器错误消息

[英]crazy C++ compiler error messages about a copy constructor from MinGW32

I'm a beginning C++ student and I'm using jGRASP and have installed MinGW32 because we turn our assignments remotely into a Linux machine so this helps ensure that it'll work properly by simulating a Linux environment in Windows or something. 我是C ++的新手,并且正在使用jGRASP并安装了MinGW32,因为我们将作业远程转换为Linux机器,因此可以通过在Windows或类似环境中模拟Linux环境来确保其正常工作。 For MinGW32 I installed the "base package" and then manually selected the C++ compiler option. 对于MinGW32,我安装了“基本软件包”,然后手动选择了C ++编译器选项。 In jGRASP I went to settings>>PATH/CLASSPATH>>workspace and added a new PATH directory to C:\\MinGW\\mingw32\\bin so that it'll know where the g++ compiler is. 在jGRASP中,我转到settings>>PATH/CLASSPATH>>workspace ,并将新的PATH目录添加到C:\\MinGW\\mingw32\\bin以便它可以知道g ++编译器的位置。

I get these crazy error messages upon compiling in jGRASP that I can't make much sense of. 在jGRASP中编译时,我会收到这些疯狂的错误消息,但我不太理解。 I think it has something to do with my header because of the iostream. 由于iostream,我认为这与我的标头有关。

#include <string.h>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

Here are the compiler error messages: 以下是编译器错误消息:

ios:42:0,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39,
                 from 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&)' is private
     ios_base(const ios_base&);
     ^
ios:44:0,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39,
                 from lab1.cpp:6:
basic_ios.h:66:11: error: within this context
     class basic_ios : public ios_base
           ^
In file included from 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,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39,
                 from 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>]' is private
       basic_streambuf(const basic_streambuf& __sb)
       ^
In file included from lab1.cpp:8:0:
fstream:72:11: error: within this 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 is my code so far: 到目前为止,这是我的代码:

// ----------------------------------------------------------------------------
// You write meaningful doxygen comments and 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 by GROUP

struct StudentType  {               // information of one student
   int grade;                       // the grade of the student
   char last[MAXLENGTH];            // last name (MAXLENGTH-1 at most)
   char first[MAXLENGTH];           // first name (MAXLENGTH-1 at 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 by GROUP
   int average = 0;                 // average exam score, truncated

   // creates file object and opens the data file
   ifstream infile("data1.txt");
   if (!infile)  { 
      cout << "File could not be opened." << endl; 
      return 1;  
   }

   // read and sort input by last then first name
   bool successfulRead = sortInput(infile, students, size);              

   // display list, histogram, and class average 
   if (successfulRead)  {
      displayList(students[], size);
     // setHistogram(... you figure parameters ...);
     // displayHistogram(... you figure parameters ...);
     // average = findAverage(... you 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 i = MAXSIZE-1; i > MAXSIZE-1-size; i--)
      for(int i = size; i > 0; i--)
      {
         if(strcmp(temp.last, students[i].last) < 0)
         {
            //copy current name and 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 and grade down
            students[i+1] = students[i];
         }
         else
         {
            //found right place, break out of loop
            break;
         }
      }

      //now that you've made room, insert (copy) new name into correct sorted position
      students[i] = temp;
   }

   return true;
}

void displayList(StudentType students[], int size)
{
   cout << "List of names sorted:" << end1;

   for(int i = 0; i < size; i++)
   {
      cout << " " << student[i].grade << " " << students[].last << " " << students[i].first << end1;
   }
}

// ----------------------------------------------------------------------------
// functions with meaningful doxygen comments and assumptions go here

I ran into this myself. 我自己遇到了这个。 The problem is that sortInput takes an ifstream by value, instead of by reference. 问题是sortInput按值而不是按引用接受ifstream ifstream s don't like to be copied. ifstream不喜欢被复制。 Just change the declaration to: 只需将声明更改为:

bool sortInput(ifstream&, StudentType, int);

Note the & 注意

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++ Mingw32 CreateProcess()失败,错误代码为2:系统找不到指定的文件 - C++ Mingw32 CreateProcess() failed with error code 2: The system cannot find the file specified 使用MINGW32在Debian上使用C ++和MySQL进行编译 - Compile with C++ & MySQL on Debian using MINGW32 GLFW链接无法在C ++中与mingw32正常使用(?) - GLFW link not working correctly with mingw32 in C++ (?) 关于编译器中缺少stdafx.h(windows上的mingw32) - About stdafx.h missing in my compiler(mingw32 on windows) 错误(mingw32/bin/ld.exe 最终链接失败:设备上没有剩余空间)构建 C++ 项目 - Error (mingw32/bin/ld.exe final link failed: No space left on device) building C++ project 与mingw32的Qt编译错误 - Qt compilation error with mingw32 使用 Cmake 编译 QtGstreamer 时出错,Mingw32 Compiler 附带 QT 5.12.3 - Error when compiling QtGstreamer using Cmake and Mingw32 Compiler comes with QT 5.12.3 在CodeLite(Windows)中将编译器从MinGW32更改为clang会导致编译错误 - Changing compiler from MinGW32 to clang in CodeLite (Windows) results in compilation errors Armadillo C ++和BLAS和ATLAS在mingw32下找不到lapack blas - Armadillo C++ and BLAS and ATLAS cannot find lapack blas under mingw32 如何减少pthread_join的影响。 Mingw32,C ++ - How can I reduce the effect of pthread_join. Mingw32, c++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM