Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: vector operator =

Reply
Thread Tools

Re: vector operator =

 
 
John Harrison
Guest
Posts: n/a
 
      08-24-2003

"Christopher" <(E-Mail Removed)> wrote in message
news:fn72b.20636$(E-Mail Removed). ..
> 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


 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-26-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM
why vector assignment operator not invoked on const vector& ? zhou C++ 9 09-02-2003 08:19 PM



Advertisments