I have a function that returns a vector of a class:
vector<movement> returnMoves(int startx, int starty, int bb[][8], int side){
vector<movement> moves;
movement adding;
moves.push_back(adding); moves.push_back(adding); //example
return moves;
}
And I am calling the function in this way from the main:
vector<movement> t1;
t1 = returnMoves(startx, starty, bb, 1);
It works, but this process is being done many many times, and it's slow, so I'd like to make it faster so I was considering returning by reference or by pointers: This is what I tried:
vector<movement> & returnMoves(int startx, int starty, int bb[][8], int side){
vector<movement> temp1;
vector<movement>& moves = temp1;
moves.push_back(adding); moves.push_back(adding);
return moves;
}
and calling it in the same way:
t1 = returnMoves(startx, starty, bb, 1);
It gives me a segmentation fault, what am I doing wrong?