lewin85_sg
asked on
How to return pointers array?
Currently I have a function that updates a linkedlist. The function prototype is as such:
struct dbLinkedlist* insertError(struct dbLinkedlist* startPtr, struct dbLinkedlist* list);
As you can see, the function now returns one pointer. I need the function to return two pointers, how should I do it?
Pls help. thx.
struct dbLinkedlist* insertError(struct dbLinkedlist* startPtr, struct dbLinkedlist* list);
As you can see, the function now returns one pointer. I need the function to return two pointers, how should I do it?
Pls help. thx.
following example code i made should help you
#include<iostream>
using namespace std;
pair<int *, int *> test(){
int *a = new int(2);
int *b = new int(3);
return(make_pair(a, b));
}
int main(){
pair<int *, int *> result = test();
cout<<"first: "<<*(result.first)<<endl;
cout<<"second: "<<*(result.second)<<endl;
}
#include<iostream>
using namespace std;
pair<int *, int *> test(){
int *a = new int(2);
int *b = new int(3);
return(make_pair(a, b));
}
int main(){
pair<int *, int *> result = test();
cout<<"first: "<<*(result.first)<<endl;
cout<<"second: "<<*(result.second)<<endl;
}
oops sorry , i thought i was in C technical area :(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you sure you need to return two pointers? I have implemented linked lists many times but didn't need that, could you give us some detail?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with jaime_olivares,
the need to return two pointers seems dubious........Although possible to do it, but just think if u really need it...
Amit
the need to return two pointers seems dubious........Although possible to do it, but just think if u really need it...
Amit
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
make a pair out of the two pointers
http://www.sgi.com/tech/stl/pair.html