tags:

views:

74

answers:

1

Hi, I've created a method which is accept parameter by reference like following :

void Func1(QList<int> *a){
 (*a) << getDataFromAnotherFunction();
//or
(*a).append(getDataFromAnotherFunction());
}

QList<int> getDataFromAnotherFunction(){

//we will do something good over here

return QList<int>
}

but the problme is when I want to use the a's data there is no data in it. and it says 0; say I want to count the element in it like following :

//for passing a to func1 I use something like that
//QList a;
//func(&a);
//after retruning from func1 now I want to use the result like  below :

a.size();

//but the answer is 0

how should I pass my parameter to get the correct data?

regards.

A: 

You probably want to do like the following:

void Func1(QList<int> &a){  // this is pass-by-reference
a << getDataFromAnotherFunction(); 
}

and then use it like this:

QList <int> my_qlist;
Func1(my_qlist);

Note that you must overload the << operator. Your current behaviour depends, from what you have written, on the fact that in getDataFromAnotherFunction you are returning an empty QList.

Francesco
Both methods are correct - pointer is good as well as reference. It won't be his problem
Gaim
@Gaim: of course, but writing explicitly in term of references seems clearer to me, and clearer code is easier to write and debug. From the example I thought that the issue was with the getDataFromAnotherFunction returning wrong data.
Francesco