vector of fstream

M

Marc Schellens

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
 
J

Jim Fischer

Marc said:
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::eek:fstream 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::eek:perator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable
 
J

John Harrison

Jim Fischer said:
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::eek:fstream 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::eek:perator=(const X&)'
x1 = x2; // ERROR -- member 'out' is not assignable

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top