A compilation error with C++: "Undefined symbols for architecture x86_64"

  accelerated-c++, c++

I tried to compile "grade.cpp" separately, but the terminal returns "Undefined symbols for architecture x86_64"; How to solve this question such that I can compile "grade.cpp" separately?

The terminal looks like this (my name is starred):

(base) ***************-MacBook-Pro ch4 % g++ grade.cpp
Undefined symbols for architecture x86_64:
  "median(std::__1::vector<double, std::__1::allocator<double> >)", referenced from:
      grade(double, double, std::__1::vector<double, std::__1::allocator<double> > const&) in grade-924066.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The "grade.cpp" is:

#include "grade.h"
#include "median.h"
#include "Student_info.h"
#include <stdexcept>
#include <vector>

using std::domain_error;
using std::vector;

int main() {
    return 0;

double grade(double midterm, double final, double homework) {
    return 0.2 * midterm + 0.4 * final + 0.4 * homework;

double grade(double midterm, double final, const vector<double>& hw) {
    if (hw.size() == 0){
        throw domain_error("student has done no homework");
    return grade(midterm, final, median(hw));

double grade(const Student_info& s) {
    return grade(s.midterm, s.final, s.homework);

The "grade.h" is:

#ifndef GUARD_grade_h
#define GUARD_grade_h

#include <vector>
#include "Student_info.h"

double grade(double, double, double);
double grade(double, double, const std::vector<double>&);
double grade(const Student_info&);


The "median.cpp" is:

#include "median.h"
#include <vector>
#include <stdexcept>
#include <algorithm>

using std::domain_error;
using std::sort;
using std::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];

The "median.h" is:

#ifndef GUARD_median_h
#define GUARD_median_h
#include <vector>

double median(std::vector<double>);


The "Student_info.cpp" is

#include "Student_info.h"

using std::istream;
using std::vector;

bool compare(const Student_info& x, const Student_info& y) {
    return x.name < y.name;

istream& read(istream& is, Student_info& s) {
    is >> s.name >> s.midterm >> s.final;
    read_hw(is, s.homework);
    return is;

istream& read_hw(istream& in, vector<double>& hw) {
    if (in) {

        double x;
        while(in >> x) {

    return in;

The "Student_info.h" is:

#ifndef GUARD_Student_info
#define GUARD_Student_info

#include <iostream>
#include <string>
#include <vector>

struct Student_info {
    std::string name;
    double midterm, final;
    std::vector<double> homework;

bool compare(const Student_info&, const Student_info&);
std::istream& read(std::istream&, Student_info&);
std::istream& read_hw(std::istream&, std::vector<double>&);

Source: Windows Questions C++