So, this is the first time I actually separated a single program into a header and two .cpp files . But I think I am getting an linkage error . Heres how the directory looks . (heres a link to my image I dont have enough rep to post image in the question)
The main.cpp is my main source file where all the calling functions and other important stuff goes . In functions.cpp I have all my functions , in the coordin.h file I have the function prototypes and structures and Constants . Everything is ok no typo nothing I have checked everything . But I am getting an undefined reference to function error. I have included the coordin.h file too . Do you think the functions.cpp file needs to go somewhere else I mean is the compiler not looking inside that file ?
Hers the code :
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;
}
Heres the error :