I cant pass fstream
as an argument to a function
Like fname(fstream , char []); /* Prototype */
fname(fstream , char []); /* Prototype */
and call fname(fs, p);
it throws error,
In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/include/c++/4.8/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
ios_base(const ios_base&);
I later learned that i have to use fstream&
. I am just wondering does streams are treated differently than objects ? if yes can someone just tell some proper source of reading so that I don't mess up again. Thanks a lot.
As the Error says
error: 'std::ios_base::ios_base(const std::ios_base&)' is private ios_base(const ios_base&);
,
fstream does not have a copy constructor (The copy constructor is defined as private). You need to pass the fstream
object by reference
rather than by value
.
This would effectively mean, your prototype signature needs to be changed
fname(fstream& , char []);
Stream object is not copiable. What should happen in your copying stream which, say, associated with a file?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.