Link to home
Start Free TrialLog in
Avatar of lewin85_sg
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.
Avatar of avizit
avizit

oen way would be to return a pair

make a pair out of the two pointers

http://www.sgi.com/tech/stl/pair.html
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;
}
oops sorry , i thought i was in C technical area :(
SOLUTION
Avatar of sneeuw_chan
sneeuw_chan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial