vector of fstream

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marc Schellens

    vector of fstream

    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

  • Jim Fischer

    #2
    Re: vector of fstream

    Marc Schellens wrote:[color=blue]
    > 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?[/color]

    The C++ iostreams classes are neither CopyConstructab le 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=(c onst X&)'
    x1 = x2; // ERROR -- member 'out' is not assignable

    --
    Jim

    To reply by email, remove "link" and change "now.here" to "yahoo"
    jfischer_link58 09{at}now.here. com


    Comment

    • John Harrison

      #3
      Re: vector of fstream


      "Jim Fischer" <jfischer_link5 809@now.here.co m> wrote in message
      news:_63Ra.2220 $C71.1413@fe01. atl2.webusenet. com...[color=blue]
      > Marc Schellens wrote:[color=green]
      > > 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?[/color]
      >
      > The C++ iostreams classes are neither CopyConstructab le 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=(c onst X&)'
      > x1 = x2; // ERROR -- member 'out' is not assignable
      >
      > --
      > Jim[/color]

      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


      Comment

      Working...