By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

vector of fstream

P: n/a
I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?
thanks,
marc

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Marc Schellens wrote:
I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?


The C++ iostreams classes are neither CopyConstructable nor Assignable.
So iostream objects cannot reside in objects / containers that require
these properties (e.g., STL containers). For example:

struct X { std::ofstream out; }

X x1, x2;

// Invoke 'X::X(const X&)' (i.e., class X's copy constructor)
X x3(x2); // ERROR -- member 'out' is not copyable

// Invoke 'X::operator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable

--
Jim

To reply by email, remove "link" and change "now.here" to "yahoo"
jfischer_link5809{at}now.here.com
Jul 19 '05 #2

P: n/a

"Jim Fischer" <jf***************@now.here.com> wrote in message
news:_6*****************@fe01.atl2.webusenet.com.. .
Marc Schellens wrote:
I have (or better had) a class wich contains
a fstream (as a private member).
I made a vector of this class.
When I resize() the vector I got several error messages,
about some stuff being private int that context.
Is this gcc (3.2) specific or is there a 'official' reason for this?


The C++ iostreams classes are neither CopyConstructable nor Assignable.
So iostream objects cannot reside in objects / containers that require
these properties (e.g., STL containers). For example:

struct X { std::ofstream out; }

X x1, x2;

// Invoke 'X::X(const X&)' (i.e., class X's copy constructor)
X x3(x2); // ERROR -- member 'out' is not copyable

// Invoke 'X::operator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable

--
Jim


All that is true, but the OP has an fstream in a class, and the class was
put in a vector. So the OP can get around this problem if he can define a
copy constructor and assignment operator for his class. Admittedly this
might be difficult.

john
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.