[英]Operator ( == ) overloading error
So, I'm working on a flowchart project(OOP), and I need to implement a condition for the GUI to let the user DrawConnector, but the "Connector" has a condition is to be drawn only when you have 2 other "Shapes" (Diamond/Rectangl/Etc.). 因此,我正在开发流程图项目(OOP),并且需要实现GUI的条件以允许用户使用DrawConnector,但是“ Connector”的条件是仅当您有另外2个“ Shape”时才绘制”(钻石/ Rectangl /等等)。
So this is the Connector Class.h 这是连接器类.h
class Connector
{
protected :
Point start;
Point end;
Statement *St;
bool DrawCondition;
bool DelCondition;
public :
Connector();
virtual void setStart(Point S); //Not a condition to be virtuals
virtual void setEnd(Point E);
virtual void DrawConnector(Output* pOut);
//virtual bool setDrawCondition ();
friend bool operator == (Point P, Point T);
};
I actually want to "setStart" and "setEnd" by the values user "Clicks" on mouse -during runtime- and check after that if these points are to be on a shape, so it draws the connector, if not, then nothing happens. 我实际上想在运行时通过鼠标上的值用户“ Clicks”来“ setStart”和“ setEnd”,然后检查这些点是否在形状上,因此它绘制了连接器,如果没有,则什么也没发生。
void Connector::setStart(Point S)
{
if (S == St->getPoint())
{start = S;}
else return;
}
void Connector::DrawConnector(Output *pOut)
{
/*if (DrawCondition == true)*/
pOut->DrawConnector(start.x,start.y,end.x,end.y);
}
You can notice I overloaded the operator " == " to check for the points if they're EVEN read ... but it ends up giving me this compilation error ! 您可能会注意到,我重载了运算符“ ==”来检查点是否已被读取...但这最终给了我这个编译错误!
Error 3 error LNK2019: unresolved external symbol "bool __cdecl operator==(struct Point,struct Point)" (??8@YA_NUPoint@@0@Z) referenced in function "public: virtual void __thiscall Connector::setStart(struct Point)" (?setStart@Connector@@UAEXUPoint@@@Z) C:\\Users\\Cereal Killer\\Downloads\\Phase1-Code\\Phase1-Code\\Connector.obj
错误3错误LNK2019:未解析的外部符号“布尔__cdecl运算符==(结构点,结构点)”(?? 8 @ YA_NUPoint @@ 0 @ Z)在函数“公共:虚拟void __thiscall Connector :: setStart(struct Point)中引用” )“(?setStart @ Connector @@ UAEXUPoint @@@@ Z)C:\\ Users \\ Cereal Killer \\ Downloads \\ Phase1-Code \\ Phase1-Code \\ Connector.obj
EDIT 编辑
Sorry guys, I forgot to mention I ALREADY defined the overloading in another file but I guess that was the problem, but why, isn't it a "GLOBAL FUNCTION" ? 抱歉,我忘了提到我已经在另一个文件中定义了重载,但是我想这是问题所在,但是为什么不是“ GLOBAL FUNCTION”呢?
Here's the def. 这是国防部。 :
:
bool operator == (Point P, Point T)
{
if ( (P.x == T.x) && (P.y == T.y) )
return true;
else return false;
}
One more thing, if I want to check that the given POINT is ON the SHAPE from the GUI shapes "DrawRectangle, DrawCircle, etc." 还有一件事,如果我想通过GUI形状“ DrawRectangle,DrawCircle等”检查给定的POINT是否位于SHAPE上。 How can I "trace the points that drawed the shape" ?
如何“追踪绘制形状的点”? Or is there another way ?
还是有另一种方法?
You have declared 您已经声明
friend bool operator == ( Point P, Point T);
but have not defined it. 但尚未定义。
You need a definition of 您需要定义
bool operator == ( Point P, Point T) {
//...
}
You need give a definition of the operator like any function, not just the declarations. 您需要像任何函数一样给运算符定义,而不仅仅是声明。 The lack thereof will generate this error.
缺少它会产生此错误。 Since it's a friend, it's just a global function, and you need to define this external to the class.
因为它是一个朋友,所以它只是一个全局函数,您需要在类外部定义此函数。 Either in the header, or in the appropriate .cpp file.
在标题中,或在适当的.cpp文件中。
bool operator==(Point P, Point T) {
return P.x == T.x && P.y == T.y;
}
You might also consider passing the points by const reference rather than value. 您可能还考虑通过const引用而不是值传递点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.