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 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
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.
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." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |