Hello :-)
I'm trying to pass a filestream to a function:
template <class T>
void grid<T>::print(std::ofstream file)
{ for (int i = 0; i < h; i++)
{ for (int j = 0; j < w; j++)
file << cell[i][j] << "\t";
file << std::endl;
}
}
so that I can do something like this:
somegrid.print(densities);
However, mu compiler gives me a lot of errors I don't understand. Can you tell me how to do it right?
Thank you!
Daan
Output from g++:
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/bits/ios_base.h:779: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd:55: error: within this context
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd: In copy constructor ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd:92: warning: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd: In copy constructor ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/streambuf:772: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]’ is private
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd:86: error: within this context
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd: In copy constructor ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/i486-linux-gnu/4.0.4/../../../../include/c++/4.0.4/iosfwd:92: warning: synthesized method ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’ first required here
SK.cpp: In function ‘int main()’:
SK.cpp:394: warning: synthesized method ‘std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(const std::basic_ofstream<char, std::char_traits<char> >&)’ first required here
SK.cpp:394: warning: initializing argument 1 of ‘void grid<T>::print(std::ofstream) [with T = double]’