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. Advertisements

  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. Advertisements

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. learningjava
    Replies:
    5
    Views:
    2,530
    Miguel De Anda
    Oct 17, 2003
  2. RC
    Replies:
    34
    Views:
    3,119
    Monique Y. Mudama
    Sep 29, 2005
  3. zhou
    Replies:
    9
    Views:
    675
    Andrey Tarasevich
    Sep 2, 2003
  4. pmatos
    Replies:
    6
    Views:
    25,564
  5. Replies:
    8
    Views:
    2,355
    Csaba
    Feb 18, 2006
  6. Chris Roth

    Vector Assign vs Vector operator=

    Chris Roth, Feb 21, 2007, in forum: C++
    Replies:
    4
    Views:
    524
    Ron Natalie
    Feb 22, 2007
  7. Javier
    Replies:
    2
    Views:
    916
    James Kanze
    Sep 4, 2007
  8. Rushikesh Joshi
    Replies:
    0
    Views:
    615
    Rushikesh Joshi
    Jul 10, 2004
Loading...