473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

passing linked lists to functions

I need to pass the STL linked list to a function, this function should
modify the linked list. So do I need to pass it by address, this is how
I do it:
void qhull(PARTICLE S[], int len, list<PARTICLE> &hull,
list<PARTICLE>::iterator
&iter1,
list<PARTICLE>::iterator &iter2, PARTICLE a, PARTICLE b,
int rank, int numtasks)

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);

Pushkar Pradhan

Jul 22 '05 #1
3 2847
"Pushkar Pradhan" <pu*****@gri.msstate.edu> wrote...
I need to pass the STL linked list to a function, this function should
modify the linked list. So do I need to pass it by address, this is how
I do it:
void qhull(PARTICLE S[], int len, list<PARTICLE> &hull,
list<PARTICLE>::iterator
&iter1,
list<PARTICLE>::iterator &iter2, PARTICLE a, PARTICLE b,
int rank, int numtasks)

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.

Victor
Jul 22 '05 #2
Pushkar Pradhan wrote:
I need to pass the STL linked list to a function, this function should
modify the linked list. So do I need to pass it by address, this is
how I do it:
void qhull(PARTICLE S[], int len, list<PARTICLE> &hull,
list<PARTICLE>::iterator
&iter1,
list<PARTICLE>::iterator &iter2, PARTICLE a, PARTICLE b,
int rank, int numtasks)
You're not passing it by address, but rather by reference.
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.
Are you sure you need both the list and the iterators? Anyway, I'd pass
them by value, since you probably have to copy them anyway.
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);


That's because hull.begin() and hull.end() return temporaries, and
you're not allowed to bind those to non-const references.

Jul 22 '05 #3
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."
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
12
by: Jonathan Bartlett | last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and thought you all might be interested. It's not an introduction -- it instead covers some of the more interesting aspects of...
3
by: Little | last post by:
Could someone help me get started on this program or where to look to get information, I am not sure how to put things together. 1. Create 4 double linked lists as follows: (a) A double linked...
1
by: Little | last post by:
Could someone help me figure out how to put my project together. I can't get my mind wrapped around the creation of the 4 double Linked Lists. Thank your for your insight. 1. Create 4 double...
3
by: Little | last post by:
Could someone tell me what I am doing wrong here about declaring mutiple double linked lists. This is what the information is for the project and the code wil be below that. Thank your soo much for...
9
by: Sheldon | last post by:
Hi, I am trying to understand linked lists and the different ways to write a linked list and double linked list. I have been trying to get this function called insert_word to work but to no...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.