I'm at a chapter on C++ where it teaches how to create a function and how codes can be separated into several files. Well, in a file that define a function in it, I'm having a problem compiling (actually, I have problems compiling for all of them). I believe I copy the codes correctly. Anyway, when I try to compile my file, I would get this error:
As the error message should indicate, I'm using Code::Blocks IDE.Code:C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `_WinMain@16'| ||=== Build finished: 1 errors, 0 warnings ===|
Anyway, this is one of the files I'm trying to compile:
The header named median.h
And here's the part of the code in a file named median.cppCode:#ifndef GUARD_median_h #define GUARD_median_h // median.h--final version #include <vector> double median(std::vector<double>); #endif
I tried adding int main() after a bit of google, but I received a different error instead...Code:#include <algorithm> #include <stdexcept> #include <vector> #include "median.h" using std::domain_error; using std::sort; using std::vector; //compute the median of a vector<double> 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]; }
What am I doing wrong?



LinkBack URL
About LinkBacks



