This book is not a easy go.
I am in chapter 4.3 and trying to compile median.cc which has included header median.h. It was actually a function in a grading program, which I was using to get the median of a vector<double> and according to book I am writing it in a separate file and trying to compile it. As a function inside the grade program it was working fine.
// source file for the median function
#include <vector> // to get the declaration of vector
#include <algorithm> // to get the declaration of sort
#include <stdexcept> // to get the declaration of domain_error
#include "median.h"
using std::domain_error; using std::sort; using std::vector;
// compute the median of a vector<double>
// note that calling this function copies the entire argument vector
double median(vector<double> vec)
{
typedef vector<double>::size_type vec_sz;
vec_sz size = vec.size();
if (size == 0)
throw domain_error("median of an empty vector");
sort(vec.begin(), vec.end());
vec_sz mid = size / 2;
return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid];
}
double median(std::vector<double>);
When I am trying to compile median.cc it giving me error
undefined references to '_WinMain@16'.
Most probably I am again doing silly mistake or something very funny, dunno.
Anyone has any idea or anyone else is using this book.