Hi, I'm really confused now about how to return an int[] from a C++ function. Inside the function, I need to dynamically resize the array, but at the end I want the variable returned to be an array, not a pointer, but I have no idea how to do this:
int findAll( string str, string sub ) {
int count = 0;
int *indices = new int[ count ];
for( int i = 0; i < str.length(); i ++ ) {
if( str.find( sub, i ) == i ) {
count += 1;
int *temp = new int[ count ];
for( int j = 0; j < count; j ++ )
temp[ j ] = indices[ j ];
delete [] indices;
indices = temp;
}
}
return indices;
}
The problem is that this gives me the error: invalid conversion from `int*' to `int'
How do I return the actual array, rather than the pointer? Thanks!