Im working on an c++ pseudo graphic button for a school assignment. I use the observer pattern.
in Button.cpp:
void Button::notify()
{
for (int iterator = 0; iterator < listeners.size(); iterator++)
{
listeners[iterator]->MousePressed(*this, x, y, isLeft);
}
}
as you can see the MousePressed function receive 4 arguments but i get:
function does not take 4 arguments
in Button.h:
struct MouseListener
{
virtual void MousePressed(Button &b, int x, int y, bool isLeft) = 0;
};
class Button : public Label
{
public:
vector <MouseListener*> listeners;
.
.
.
in main:
struct MyListener : public MouseListener
{
MyListener(iControl &c) : _c(c) { }
void MousePressed(Button &b, int x, int y, bool isLeft)
{
_c.setForeground(Color::Red);
}
private:
iControl &_c;
};
int main(VOID)
{
errors:
Error 2 error C2061: syntax error : identifier 'Button' c:\users\gonen\unitedproj\unitedproj\Button.h 14 1 unitedProj
Error 4 error C2061: syntax error : identifier 'Button' c:\users\gonen\unitedproj\unitedproj\Button.h 14 1 unitedProj
Error 5 error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments C:\Users\Gonen\unitedProj\unitedProj\Button.cpp 24 1 unitedProj
when the first two are for the declartion in main and the last is in the use of the function in Button.cpp. help? when im standing with the mouse curser on the function in Button.cpp i get:
void MouseListener::MousePressed(Button &b,int x,int y, bool isLeft)
I just need this to work so i can move on and let the rest of the group members to use the button in the controls they implementing... and move on to the next i need to do :-(
edit: thank you for the fast answer. I tried to do what you asked. now i get:
*Error 3 error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup C:\Users\Gonen\unitedProj\unitedProj\MSVCRTD.lib(crtexe.obj) unitedProj
Button
is not declared at the point where MousePressed
is declared, so it cannot be used. I suggest you should use forward declaration.
class Button; // add this line
struct MouseListener
{
virtual void MousePressed(Button &b, int x, int y, bool isLeft) = 0;
};
class Button : public Label
{
public:
vector <MouseListener*> listeners;
.
.
.