c ++未定义的类引用

时间:2016-11-28 03:58:44

标签: c++

主     #include

#include "Polar.hpp"
using namespace std;
int main(void)
{
Polar points[2];
for(int i = 0; i<2;i++)
{
float r, theta;
cin>>r>>theta;
points[i]=Polar(r,theta);
}
const Polar sum = points[0] + points[1];
cout<<sum<<"=="<<points[0]<<"+"<<points[1]<<endl;
return 0;
}

Polar.hpp

#include <iostream>
#include <math.h>
#include <cmath>
#include <string>
#ifndef POLAR_H
#define POLAR_H
using namespace std;

class Polar
{
public:
    Polar(void);//theta in degrees
    Polar(const float r , const float theta);

    float radius(void) const;
    float angle(void) const;
    friend Polar operator +(Polar p1,Polar p2);
    friend ostream& operator<<(ostream & os, const Polar & point);

    private:
        float r,theta,_r,_theta;
};

#endif // POLAR_H

Point.hpp

#include <iostream>
#include "Polar.hpp"
#include <math.h>
#include <cmath>
#include <string>
using namespace std;

Polar::Polar(void)
{
 _r=_theta=0.0;//theta in degrees
}

Polar::Polar(const float r , const float theta)
{
_r=r;
_theta=theta;
}

 float Polar:: radius(void) const
{
return _r;
}
    float Polar::angle(void) const
{
return _theta;
}
ostream & operator<<(ostream & os, const Polar & point)
{
    os<<"(" << point.radius()<<"," <<point.angle() << ")";
    return os;
}
Polar operator +(Polar p1,Polar p2)
{      float x,y;
       Polar p3;
    x=(p1._r*cos(p1._theta*3.14159/180))+                                                         (p2._r(cos(p2._theta*3.14159/180)));

    y=(p1._r*sin(p1._theta*3.14159/180))+(p2._r*     (sin(p2._theta*3.14159/180)));
p3._r=sqrt(x*x+y*y);
   p3._theta=atan(y/x)*180/3.14159;

return p3;
}

我的程序包括主程序和类 我的程序有错误 喜欢 main.cpp :(。text + 0x181):未定义引用Polar::Polar()' main.cpp:(.text+0x292): undefined reference to Polar :: Polar(float,float)&#39; main.cpp :(。text + 0x398):未定义引用`operator +(Polar,Polar)&#39;

我真的不知道如何解决它:(

0 个答案:

没有答案