0
所以,這是我第一次實際上將一個程序分成一個頭文件和兩個.cpp文件。但我認爲我正在發生連接錯誤。下面介紹目錄的外觀。 (繼承人我的圖片鏈接我沒有足夠的代表處發佈的問題,圖像)C++鏈接錯誤。我究竟做錯了什麼?
的main.cpp中是我的主源文件,所有的通話功能和其他重要的東西去。在functions.cpp中,我有我所有的函數,在coordin.h文件中我有函數原型和結構以及常量。一切都好,沒有錯別字,我已經檢查了一切。但是我得到了一個未定義的函數錯誤的參考。 我也包含了coordin.h文件。 你認爲functions.cpp文件需要去其他地方我的意思是編譯器不在該文件中查找?
赫斯的代碼:
main.cpp中
#include <iostream>
#include "coordin.h"
using namespace std;
int main()
{
rect rplace ;
polar pplace;
rect test = {45.89,25.4};
pplace = rect_to_polar(test);
cout<<pplace.angle<<endl;
return 0;
}
coordin.h
#ifndef COORDIN_H_INCLUDED
#define COORDIN_H_INCLUDED
/* Constants */
const double RAD_TO_DEG = 57.29577951;
struct polar{
double distance; //distance from the origin
double angle; //the angle from the origin
};
struct rect {
double x; //horizontal distance form the origin
double y; //vertical distance from the origin
};
/* Function prototypes */
polar rect_to_polar(rect xypos);
void show_polar(polar dapos);
#endif // COORDIN_H_INCLUDED
functions.cpp
/*
functions.cpp
contains all the function declarations
*/
#include <iostream>
#include "coordin.h"
#include <cmath>
using namespace std;
//convert rectangular to polar coordinates
polar rect_to_polar(rect xypos){
polar answer;
answer.distance =
sqrt(xypos.x * xypos.x + xypos.y * xypos.y);
answer.angle = atan2(xypos.y, xypos.x);
return answer;
}
//show polar coordinate, converting angle to degrees
void show_polar(polar dapos){
cout<<"Distance : " << dapos.distance <<endl;
cout<<"Angle : " << dapos.angle * RAD_TO_DEG <<" degrees."<<endl;
}
繼承人的錯誤:
你在哪裏包含了coordin.h? –
錯誤究竟是什麼?你能告訴我們你的代碼嗎? – birryree
你可能有一個函數,你在'coordin.h'中提供了一個原型,但在'functions.cpp'中沒有實現。確保在'functions.cpp'中實現了你得到錯誤的確切函數(具有相同的參數和全部)。 – Gorpik