Re: Pointer To A Vector Elements While Still Adding

From: Ivan Vecerina (INVALID_use_webform_instead_at_vecerina.com)
Date: 03/27/05


Date: Sun, 27 Mar 2005 12:20:43 +0200


"Ioannis Vranos" <ivr@remove.this.grad.com> wrote in message
news:1111912117.230641@athnrd02...
> Ivan Vecerina wrote:
>>> pointerClass[i].addPointer(newlist.end()) ;
>>
>> I think this is incorrect: Adam would not want to push end(),
>> but (end()-1)
>
> You are right.
>
>> - which cannot be written as is because list
>> does not provide a random-access iterator.

Why did you 'snip' here these two lines from my previous post?
: The following would compile (for iterators that are not built-in types):
: pointerClass[i].addPointer( --newlist.end() ) ;

> It can be written as:
> pointerClass[i].addIterator(--newlist.end());
We knew ;)

>>>pointerClass[i].addPointer( &newlist.back() );
>>
>> Yep -- and this is not necessarily an inferior solution...
>
> Well if you consider that you can increment the stored iterator to
> access the next element or decrement it to access the previous element,
> while you can't do
> that with the pointers,
If that is the case, the iterator is the obvious choice.

> I can not see any real benefit of using pointers.

Using pointers:
 - avoids exposing they type of container used for the storage
   of the elements (encapsulation, fewer dependencies)
 - allows you to use containers other than std::list
   (such as std::deque, which could be preferred)

> [I am using 90 characters word-wrapping - (800/640) *72= 90. If someone
> finds it inconvenient, please let me know].
I don't think it is a good idea, because quotes of most of your
lines will get truncated by other NG engines that wrap at
a shorter line length...

Cheers,
Ivan

-- 
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form


Relevant Pages

  • Re: STL Vector: Unexpected behavior
    ... iterator of that container. ... you could move all pointers you want to keep to a new ... you also omit checking if the pointer is zero in your loop. ...
    (microsoft.public.vc.stl)
  • Re: std::container::iterator vs std::container::pointer
    ... > As far as I can tell an iterator has all the operations of a pointer like ... pointers (often found for vector container implementations). ... You might find implementations where the following line is valid: ...
    (comp.lang.cpp)
  • Re: Help understanding pointers to classes within containers...
    ... deancoo wrote: ... The problem is that j is an iterator into the container of pointers. ... If you do *j then you get one of the pointers stored in the container. ...
    (comp.lang.cpp)
  • Call for suggestions: Declaring data entry forms using Python classes
    ... For the purposes of GUI description, ... the renderer has to iterate over its fields. ... # instantiated as objects inside the container classes ... # I'm trying several versions of the iterator interface, ...
    (comp.lang.python)
  • Re: Maintance of c++ code
    ... because templates are not a method of implementing ... container, some only work with particular containers. ... inverting itself into an iterator of the opposite direction. ... explicit range(int end); ...
    (comp.object)