Y
ypjofficial
Hello All,
I need to return a vector from a function.The vector is of int and it
can contain as many as 1000 elements.Earlier I was doing
//function definition
vector<int> retIntVector()
{
vector<int> vecInt;
/*
//Populate the vector with int values.
*/
...
....
return vecInt;
}
//end function Definition
int main()
{
vector<int> vect_int = retIntVector();
...
...
return 1;
}
//Program End
But I tempt to use a reference to vector returned by the function to
enhance the performance
like
vector<int> & vect_int =retIntVector();
But somehow I could not convince myself over using this approach as in
this case there is no concrete object to which the vect_int refer.
I want to ask you whether the later approach is correct or not?
I ran it on msvc 6 and it gave me fine results..
Thanks and Regards,
Yogesh Joshi
I need to return a vector from a function.The vector is of int and it
can contain as many as 1000 elements.Earlier I was doing
//function definition
vector<int> retIntVector()
{
vector<int> vecInt;
/*
//Populate the vector with int values.
*/
...
....
return vecInt;
}
//end function Definition
int main()
{
vector<int> vect_int = retIntVector();
...
...
return 1;
}
//Program End
But I tempt to use a reference to vector returned by the function to
enhance the performance
like
vector<int> & vect_int =retIntVector();
But somehow I could not convince myself over using this approach as in
this case there is no concrete object to which the vect_int refer.
I want to ask you whether the later approach is correct or not?
I ran it on msvc 6 and it gave me fine results..
Thanks and Regards,
Yogesh Joshi