The following is the code I've written in an implementation file for a function that calculates median of a double vector :
#include<algorithm>
#include<stdexcept>
#include<vector>
#include "median.h"
using std::domain_error;
using std::vector;
double median(vector<double> vect)
{
typedef vector<double>::size_type vec_sz;
vec_sz size=vect.size();
if(size==0)
throw domain_error("median of an empty vector");
sort(vect.begin(),vect.end());
vec_sz mid= size/2;
return size%2==0 ? (vect[mid]+vect[mid-1])/2 : vect[mid];
}
I get the following when I compile it using g++ median.cpp on the command line:
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status