Coping with Accelerated c++

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.


median.cc code is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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>);


and this is median.h

1
2
3
4
5
6
7
8
9
#ifndef GUARD_median_h
#define GUARD_median_h

// median.h—final version
#include <vector>
double median(std::vector<double>);

#endif


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.

Thanx and Regards
This link error means that your project does not have main function.
@Denis
Thanx for the response. I've got the clue.

I'll have to put all files together and build project rather then compiling them individually. Am I right?

I've done it and it is ok working fine.




The difference is in the type of application you are writing.

Your IDE thinks you are trying to write a Windows GUI application.

Make sure that when you start a new project, you choose a "Console Application" project.

Hope this helps.
@Duoas

In 4 chapters I have stuck twice and still many to go. So I will keep buzzing you guys.

Thanx for your help.
Last edited on
Topic archived. No new replies allowed.