Re: vector operator =

Discussion in 'C++' started by John Harrison, Aug 24, 2003.

  1. "Christopher" <> wrote in message
    news:fn72b.20636$...
    > I am trying to make a copy constructor for a class that contains a vector
    > for a data member. If I just do lhs.theVector = rhs.theVector will it do a
    > deep copy and will the data in lhs still be safe when rhs deconstucts?


    Yes

    > I am
    > reading a doc for vectors and it is saying "All constructors copy N

    elements
    > and perform no interim reallocation", but I don't know what interim
    > reallocation means.


    I think it means any necessary allocation will be performed in one go at the
    start of the copy.

    > Will all the STL containers behave in the same manner as
    > it relates to this question?


    Yes, except possibly std::string which might use reference counting with
    copy on write rather than a deep copy. Either way the observable behaviour
    is the same.

    > Thanx,
    > Christopher
    >


    john
     
    John Harrison, Aug 24, 2003
    #1
    1. Advertising

  2. John L Fjellstad wrote:

    > John Harrison wrote:
    >
    >
    >>Yes, except possibly std::string which might use reference counting with
    >>copy on write rather than a deep copy. Either way the observable behaviour
    >>is the same.

    >
    >
    > Is std::string considered a standard container, though?
    >


    Sort of. Not really. Stroustrup classifies it as an "almost container".
    It has many of the properties of containers, but not all. It can be used
    by many of the standard algorithms. I'm not sure off the top of my head
    what it is that disqualifies it as a "real" container.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Aug 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. zhou
    Replies:
    9
    Views:
    472
    Andrey Tarasevich
    Sep 2, 2003
  2. pmatos
    Replies:
    6
    Views:
    23,953
  3. Replies:
    8
    Views:
    1,967
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    585
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    375
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page