I'm trying to return a vector from a function. My code compiles and I've checked my function and reckon that the error comes from the return part. It compiles fine (using Cygwin) but when running it, I get an Aborted (core dumped) error. Here is my code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//function that returns the square
int f(int n)
{
return n*n;
}
vector<int> myVec;
int counter = 0;
//function that uses f on all elements in a list
vector<int> map(vector<int> something)
{
//base case
if(counter == something.size())
{
/*cout << "hello" << endl;
for (int i=0; i<counter; i++)
{
cout << "vector: " << myVec[i] << endl;
}*/
counter=0;
return myVec;
}
//recursion
else
{
//cout << "counter: " << counter << endl;
int n = f(something[counter]);
//cout << "n: " << n << endl;
myVec.push_back(n);
//cout << "vector: " << myVec[counter] << endl;
counter++;
map(something);
}
}
int main()
{
//making vectors
vector<int> L;
vector<int> L1;
vector<int> L2;
for (int i=0; i<20; i++)
{
L.push_back(i);
}
L1 = map(L);
}
The code was originally from a class file.
-Wallwhen compiling and just get a warning about comparison of signed and unsigned integers and a warning about control reaches end of non-void function.