[C++] error: 'std::ios_base::ios_base(const std::ios_base&)' is private
Ostatnio zmodyfikowano 2013-01-31 07:32
MordiJC Temat założony przez niniejszego użytkownika |
[C++] error: 'std::ios_base::ios_base(const std::ios_base&)' is private » 2013-01-30 23:01:57 Witam. Mam pewien problem z użyciem mojej klasy: #include <iostream> #include <fstream> #include <vector> #include <string.h> using namespace std; class Config { private: string Line; char * cLine; fstream FileStream; vector < string > Sections; vector < string > Vars; vector < string > Vals; string Err; string sSect; void parse() { int Opt = 0; while( !this->FileStream.eof() ) { getline( this->FileStream, Line ); for( int j = 0; j <( int ) this->Line.size(); j++ ) { switch( this->Line[ j ] ) { case '#': case ';': case '/': if( j == 0 ) break; break; case '[': if( j == 0 ) { sSect.clear(); for( int k = 1; k <( int ) this->Line.size(); k++ ) { if( Line[ k ] != ']' ) this->sSect += this->Line[ k ]; else break; } this->Sections.push_back( this->sSect ); } break; default: if( j == 0 ) { this->cLine =( char * ) this->Line.c_str(); Vars[ Opt ] = strtok( cLine, "=" ); Vals[ Opt ] = strtok( NULL, "=" ); } break; } } } } public: vector < string > strx() { return Sections; } Config( string file ) { this->FileStream.open( file.c_str(), ios::in | ios::binary ); } ~Config() { if( this->FileStream.good() ) this->FileStream.close(); } }; int main() { Config c = Config( "config.txt" ); return 0; } Zwraca błąd kompilacji: D:\- - - [ D A T A ] - - -\C++\CBFiles\Testy\Config.hpp|15|warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\ios_base.h|788|error: 'std::ios_base::ios_base(const std::ios_base&)' is private| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\basic_ios.h|64|error: within this context| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|761|note: synthesized method 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' first required here | c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\streambuf|800|error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const __streambuf_type&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_streambuf<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]' is private| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|69|error: within this context| c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\fstream|761|note: synthesized method 'std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)' first required here | D:\- - - [ D A T A ] - - -\C++\CBFiles\Testy\main.cpp|8|note: synthesized method 'std::basic_fstream<char>::basic_fstream(const std::basic_fstream<char>&)' first required here | D:\- - - [ D A T A ] - - -\C++\CBFiles\Testy\main.cpp||In function 'int main()':| D:\- - - [ D A T A ] - - -\C++\CBFiles\Testy\main.cpp|81|note: synthesized method 'Config::Config(const Config&)' first required here | ||=== Build finished: 4 errors, 1 warnings (0 minutes, 1 seconds) ===|
Możecie temu zaradzić? |
|
DejaVu |
» 2013-01-30 23:30:01 Napisz: Config c( "config.txt" );
Nie można wywoływać konstruktora kopiującego dla std::fstream, a ten z kolei był wywoływany przy Twoim zapisie. |
|
ligras |
» 2013-01-30 23:30:46 A przypadkiem powołanie zmiennej nie powinno wyglądać tak: Config c( "config.txt" );
|
|
MordiJC Temat założony przez niniejszego użytkownika |
» 2013-01-31 07:32:12 Dzięki za pomoc. Zapomniałem, że nie mogę tworzyć w ten sposób obiektu. :D Teraz wszystko działa i zamierzam kontynuować pracę nad plikiem. |
|
« 1 » |