[英]error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments
Im working on an c++ pseudo graphic button for a school assignment. 我正在为学校作业使用c ++伪图形按钮。 I use the observer pattern.
我使用观察者模式。
in Button.cpp: 在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: 如您所见,MousePressed函数接收4个参数,但我得到:
function does not take 4 arguments
函数不带4个参数
in Button.h: 在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
错误2错误C2061:语法错误:标识符'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
错误4错误C2061:语法错误:标识符'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
错误5错误C2660:'MouseListener :: MousePressed':函数未采用4个参数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. 前两个用于main中的声明,最后一个用于Button.cpp中的函数。 help?
救命? when im standing with the mouse curser on the function in Button.cpp i get:
当我将鼠标光标放在Button.cpp中的函数上时,我得到:
void MouseListener::MousePressed(Button &b,int x,int y, bool isLeft)
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
*错误3错误LNK2019:函数__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. 在声明
MousePressed
的位置未声明Button
,因此无法使用它。 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;
.
.
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.