Greetings. I have several classes that manipulate certain files, and each of these classes has an fstream as one of the variables. Here are boiled-down versions of some definition and implementation files:
The command g++ -c FileX.cpp works fine; however, the command g++ -c FileY.cpp gives the following error:
FileY.cpp: 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/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/ios_base.h:784: error: `std::ios_base& std::ios_base::operator=(const std::ios_base&)' is private
FileY.cpp:18: error: within this context
FileY.cpp: 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/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/streambuf:776: 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
FileY.cpp:18: error: within this context
It appears to me that the problem is with the copy of the fstream part of the FileX object. Does anyone have suggestions as to how to fix this problem? Thanks.
Thanks for your replies. Now I have a follow-up question. I have decided to have an fstream* instead of an fstream in FileX, as shown below. I added an fstream& argument to the constructor, which I intend to have set a file name, open a file, and set a pointer to this fstream. I have added two more functions, one which is supposed to write the number 5 to the file and one which is supposed to read it. The program compiles, but when it is run it does not create the file. Here is
the code: