我有三个.cpp
文件和two header files.
但是当我编译它们时,意思是Point.cpp
, Data.cpp
and main.cpp
,它会说
main.cpp: undefined reference to "PointD::PointD()' collect2: ld returned 1 exit status
下面是我的Data.h
:
#include <iostream>
#include <string>
using namespace std;
class Data
{
private:
string sType;
public:
Data();
Data(string);
void setSType(string);
string getSType();
};
下面是我的data.cpp
:
#include "Data.h"
Data::Data()
{
sType = "";
}
Data::Data(string s)
{
sType = s;
}
void Data::setSType(string ss)
{
sType = ss;
}
string Data::getSType()
{
return sType;
}
下面是我的PointD.h
:
#include <iostream>
#include <string>
#include "Data.h"
using namespace std;
class PointD
{
private:
int x
Data data1;
public:
PointD();
PointD(int,Data);
void setX(int);
void setData(Data);
int getX();
Data getData();
};
下面是我的PointD.cpp
:
#include "PointD.h"
PointD::PointD()
{
x = 0;
}
PointD::PointD(int xOrdinate,Data dd)
{
x = xOrdinate;
data1 = dd;
}
void PointD::setXordinate(int Xordinate)
{
x = Xordinate;
}
void PointD::setData(Data dd)
{
data1 = dd;
};
int PointD::getXordinate()
{
return x;
}
Data PointD::getData()
{
return data1;
}
这是我的main.cpp
:
#include <iostream>
#include <string>
#include "Data.h"
#include "PointD.h"
using namespace std;
int main()
{
const int MAX_NUM = 20;
Data ldata[MAX_NUM];
PointD pointd[MAX_NUM];
//more codes..
}
但是当我编译它们时,意味着Point.cpp
, Data.cpp
and main.cpp
,它会说
main.cpp:未定义对“PointD::PointD()”的引用 collect2:ld 返回 1 个退出状态