Reputation: 39
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.).
So this is the Connector Class.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.
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
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" ?
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." How can I "trace the points that drawed the shape" ? Or is there another way ?
Upvotes: 0
Views: 85
Reputation: 2306
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.
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.
Upvotes: 0
Reputation: 29724
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) {
//...
}
Upvotes: 1