我有两个类Triangle
,ALine
并且我想将新ALine
实例分配给Triangle
其构造函数中的属性。但我收到了这个错误
Undefined symbols for architecture x86_64:
"ALine::ALine()", referenced from:
Triangle::Triangle(triangle) in Triangle.o
ld: symbol(s) not found for architecture x86_64
下面是我写的代码:
ALine.cpp
#include "Geometry.h"
#include "ALine.h"
ALine::ALine(point a, point b)
{
double tmpy = a.y - b.y;
double tmpx = a.x - b.x;
double tmpk;
if(equals(tmpy, 0))
{
tmpk = 0;
}
else
{
tmpk = tmpx/tmpy;
}
double tmpq = a.y - tmpk*a.x;
if(equals(tmpx, 0))
{
if(equals(a.x, 0))
{
if(equals(b.x, 0)) tmpk = 0;
else tmpk = (b.y-tmpq)/b.x;
}
else
{
tmpk = (a.y-tmpq)/a.x;
}
}
a = a;
b = b;
k = tmpk;
q = tmpq;
};
ALine.h
class ALine{
private:
double k;
double q;
point a;
point b;
double length;
void calculateLength();
public:
ALine(point a, point b);
ALine();
point getK();
point getQ();
static bool areinline(point a, point b, point c);
};
三角形.cpp
#include "Triangle.h"
#include "Geometry.h"
#include "ALine.h"
Triangle::Triangle(triangle t)
{
triangle itself = t;
a = *new ALine(itself.a, itself.b);
b = *new ALine(itself.b, itself.a);
c = *new ALine(itself.c, itself.a);
};
注意,类不完整,我在这里只粘贴了与我的问题相关的代码(如果没有,我可以添加更多)。