Re: Pointer to vector element
From: Nick Hounsome (nh002_at_blueyonder.co.uk)
Date: 03/14/04
- Next message: Pete Vidler: "Re: Question about "Named Constructor Idiom""
- Previous message: Pete Vidler: "Question about "Named Constructor Idiom""
- In reply to: yeugen: "STL : Pointer to vector element"
- Next in thread: Jason: "Re: STL : Pointer to vector element"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 14 Mar 2004 16:04:08 -0000
"yeugen" <yeugen@phreaker.net> wrote in message
news:d1a0bc8a.0403140552.67e8c607@posting.google.com...
> Simple question:
>
> Does a pointer to an element of a vector remain valid after calling
> my_vector.push_back(my_data); ?
As others have pointed out - it does if my_vector.capacity() >
my_vector.size() prior to the
push_back.
> I thought it did, but have had some problems in a program I'm writing,
> so I wrote a small program to test this:
Beware! You cannot 'prove' this sort of proposition with a test program.
The result of your test program will depend on the initial capacity of the
vector
which is undefined hence the behaviour of your program is undefined and
hence
it proves nothing.
There is no substitute for reading the documentation.
- Next message: Pete Vidler: "Re: Question about "Named Constructor Idiom""
- Previous message: Pete Vidler: "Question about "Named Constructor Idiom""
- In reply to: yeugen: "STL : Pointer to vector element"
- Next in thread: Jason: "Re: STL : Pointer to vector element"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|