Re: passing linked lists to functions

From: Unforgiven (jaapd3000_at_hotmail.com)
Date: 11/26/03


Date: Wed, 26 Nov 2003 23:28:08 +0100

Victor Bazarov wrote:
>> I think that's working but I have another problem: I need to pass two
>> iterators also to this function which point to certain position in
>> the list, should these iterators be passed by reference. The above
>> syntax gives me syntax errors:
>> This is the call from main:
>> qhull(S1, index1, hull, hull.begin(), hull.end(), globalMin,
>> globalMax, rank,
>> numtasks);
>
> 'begin' and 'end' members return a _temporary_ iterator, which cannot
> be passed where a _non_const_ reference is expected. Change your
> 'qhull' function to accept " list<PARTICLE>::iterator const& " for
> both 'iter1' and 'iter2' arguments, and it will work.

That doesn't sound like a good idea to me, because you wouldn't be able to
call any non-const members, and I suppose (especially since his example call
uses begin() and end()) that he's going to want to use operator++, which is
non-const. Just pass the iterators by value, that should do the trick.

-- 
Unforgiven
"You can't rightfully be a scientist if you mind people thinking
you're a fool."


Relevant Pages

  • Re: D foreach
    ... of 'reference to variable', which has lots of repercussions for reference counting, garbage collection etc. Requiring iterators to return references would also break all existing iterators. ... It violates the Zen of Python 'Explicit is better than implicit' (although the definition of 'explict' varies wildly in the Python community) ...
    (comp.lang.python)
  • Re: std::set sorting mechanism
    ... > Victor Bazarov wrote: ... There is an embedded conflict in the description of iterators of 'set'. ... be a reference to a non-const object). ... force at least a re-check of the "structural integrity" of the container. ...
    (comp.lang.cpp)
  • Re: Invalid initialization of non-const reference
    ... > Alf P. Steinbach wrote: ... but the iterators are temporary. ... > I guess iterators are small enough that passing them by value is as ... > fast/faster than passing them by reference? ...
    (comp.lang.cpp)
  • Re: passing linked lists to functions
    ... > modify the linked list. ... You're not passing it by address, but rather by reference. ... should these iterators be passed by reference. ...
    (comp.lang.cpp)
  • Re: passing linked lists to functions
    ... > modify the linked list. ... should these iterators be passed by reference. ... > gives me syntax errors: ...
    (comp.lang.cpp)