これはおそらく本当に簡単ですが、C++の道を進む途中で私を妨げています。私は現在、高速化されたc ++を読んでおり、演習の1つをやりすぎることにしました。それはすべてうまく機能し、ヘッダーと個別のソースファイルに分割するまでコードは正常に実行されました。作成したいくつかの関数を含む.cppソースファイルをインポートすると、すべてが正常に実行されます。しかし、ヘッダーファイルを介して関数をインポートしようとすると、ひどく失敗し、次のエラーが発生します。私はGeanyのgccでコンパイルしていますが、これまではすべて正常に機能していました。助けてくれてありがとう。
エラー:
g++ -Wall -o "quartile" "quartile.cpp" (in directory: /home/charles/Temp)
Compilation failed.
/tmp/ccJrQoI9.o: In function `main':
quartile.cpp:(.text+0xfd): undefined reference to `quartile(std::vector<double, std::allocator<double> >)'
collect2: ld returned 1 exit status
"stats.h":
#ifndef GUARD_stats_h
#define GUARD_stats_h
#include <vector>
std::vector<double> quartile(std::vector<double>);
#endif
"stats.cpp":
#include <vector>
#include <algorithm>
#include "stats.h"
using std::vector; using std::sort;
double median(vector<double> vec){
//code...
}
vector<double> quartile(vector<double> vec){
//code and I also reference median from here.
}
"quartile.cpp":
#include <iostream>
#include <vector>
#include "stats.h" //if I change this to "stats.cpp" it works
using std::cin; using std::cout;
using std::vector;
int main(){
//code and reference to quartile function in here.
}