LNK2005
像这样的错误:
error LNK2005: "public: double __thiscall Point::GetX(void)const " (?GetX@Point@@QBENXZ) already defined in CppSandbox.obj
Point.obj
)
最后一个错误是:
error LNK1169: one or more multiply defined symbols found
CppSandbox.exe
. 我不确定是什么原因导致这个错误-它似乎发生在我建立或重建解决方案。。。说实话,我真的很茫然。
下面的三个文件是我添加到默认VS2010 blank项目中的全部文件(它们是完整复制的)。谢谢你的帮助。
h点
class Point
{
public:
Point()
{
x = 0;
y = 0;
};
Point(double xv, double yv)
{
x = xv;
y = yv;
};
double GetX() const;
void SetX(double nval);
double GetY() const;
void SetY(double nval);
bool operator==(const Point &other)
{
return GetX() == other.GetX() && GetY() == other.GetY();
}
bool operator!=(const Point &other)
{
return !(*this == other);
}
private:
double x;
double y;
};
点.cpp
#include "Point.h"
double Point::GetX() const
{
return x;
}
double Point::GetY() const
{
return y;
}
void Point::SetX(double nv)
{
x = nv;
}
void Point::SetY(double nv)
{
y = nv;
}
// CppSandbox.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "Point.cpp"
int main()
{
Point p(1, 2);
Point q(1, 2);
Point r(2, 3);
if (p == q) std::cout << "P == Q";
if (q == p) std::cout << "Equality is commutative";
if (p == r || q == r) std::cout << "Equality is broken";
return 0;
}