473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2858
"Pushkar Pradhan" <pu*****@gri.ms state.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
4814
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 ordered by my instructor and she does have her reasons so I have to use char*. So there is alot of c in the code as well Anyways, I have a linked...
10
15113
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 *enemydata; // Holds information about an enemy (in a game) // Its a double linked list node
6
4590
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 potential pitfalls I'd be extremely grateful. Cheers Steve
12
2499
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 linked lists. http://www.ibm.com/developerworks/linux/library/l-listproc/ Jon ---- Learn to program using Linux assembly language...
3
3315
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 list called NAMES which will contain all C like identifiers of less than 256 characters long identified in the input file F. Each identifier will...
1
4146
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 linked lists as follows: (a) A double linked list called NAMES which will contain all C like identifiers of less than 256 characters long...
3
472
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 your assitance in helping me solve this problem. Information: Create 4 double linked lists as follows: (a) A double linked list called...
9
4893
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 avail. The function receives a string from main and then inserts in the list the new word in alphabetical order. Here is my function: struct word { ...
0
8616
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 anything from a short integer value to a complex struct type, also has a pointer to the next node in the single-linked list. That pointer will be NULL...
0
8216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.