Hi. I need to use a fstream variable for each instance of my class but...
#include <fstream>
class MyClass {
public:
MyClass(bool bKernel) {
}
std::fstream fichier;
};
int main() {
MyClass module(false);
module = new MyClass(true);
return 0;
}
This one wont work printing some weird errors :
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"toto.d" -MT"toto.d" -o"toto.o" "../toto.cpp"
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/ios_base.h: In member function ‘std::basic_ios<char, std::char_traits<char> >& std::basic_ios<char, std::char_traits<char> >::operator=(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/ios_base.h:782: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:55: error: within this context
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: In member function ‘std::basic_istream<char, std::char_traits<char> >& std::basic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:61: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >& std::basic_ios<char, std::char_traits<char> >::operator=(const std::basic_ios<char, std::char_traits<char> >&)’ first required here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: In member function ‘std::basic_iostream<char, std::char_traits<char> >& std::basic_iostream<char, std::char_traits<char> >::operator=(const std::basic_iostream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:67: note: synthesized method ‘std::basic_istream<char, std::char_traits<char> >& std::basic_istream<char, std::char_traits<char> >::operator=(const std::basic_istream<char, std::char_traits<char> >&)’ first required here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: In member function ‘std::basic_fstream<char, std::char_traits<char> >& std::basic_fstream<char, std::char_traits<char> >::operator=(const std::basic_fstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:95: note: synthesized method ‘std::basic_iostream<char, std::char_traits<char> >& std::basic_iostream<char, std::char_traits<char> >::operator=(const std::basic_iostream<char, std::char_traits<char> >&)’ first required here
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/streambuf: In member function ‘std::basic_filebuf<char, std::char_traits<char> >& std::basic_filebuf<char, std::char_traits<char> >::operator=(const std::basic_filebuf<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/streambuf:789: error: ‘std::basic_streambuf<_CharT, _Traits>& std::basic_streambuf<_CharT, _Traits>::operator=(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]’ is private
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:86: error: within this context
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd: In member function ‘std::basic_fstream<char, std::char_traits<char> >& std::basic_fstream<char, std::char_traits<char> >::operator=(const std::basic_fstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/iosfwd:95: note: synthesized method ‘std::basic_filebuf<char, std::char_traits<char> >& std::basic_filebuf<char, std::char_traits<char> >::operator=(const std::basic_filebuf<char, std::char_traits<char> >&)’ first required here
../toto.cpp: In member function ‘MyClass& MyClass::operator=(const MyClass&)’:
../toto.cpp:3: note: synthesized method ‘std::basic_fstream<char, std::char_traits<char> >& std::basic_fstream<char, std::char_traits<char> >::operator=(const std::basic_fstream<char, std::char_traits<char> >&)’ first required here
../toto.cpp: In function ‘int main()’:
../toto.cpp:15: note: synthesized method ‘MyClass& MyClass::operator=(const MyClass&)’ first required here
make: *** [toto.o] Erreur 1
But if I declare the fstream outside of the class' scope, it will work :
#include <fstream>
std::fstream fichier;
class MyClass {
public:
MyClass(bool bKernel) {
}
};
int main() {
MyClass module(false);
module = new MyClass(true);
return 0;
}
Can you help me about that ?