繁体   English   中英

错误C2660:'MouseListener :: MousePressed':函数未采用4个参数

[英]error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments

我正在为学校作业使用c ++伪图形按钮。 我使用观察者模式。

在Button.cpp中:

void Button::notify()
{
    for (int iterator = 0; iterator < listeners.size(); iterator++)
    {
        listeners[iterator]->MousePressed(*this, x, y, isLeft);
    }
}

如您所见,MousePressed函数接收4个参数,但我得到:

函数不带4个参数

在Button.h中:

struct MouseListener
{
    virtual void MousePressed(Button &b, int x, int y, bool isLeft) = 0;
};

class Button : public Label
{
public:

    vector <MouseListener*> listeners;
.
.
.

在主要方面:

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)
{

错误:

  • 错误2错误C2061:语法错误:标识符'Button'c:\\ users \\ gonen \\ unitedproj \\ unitedproj \\ Button.h 14 1 unitedProj

  • 错误4错误C2061:语法错误:标识符'Button'c:\\ users \\ gonen \\ unitedproj \\ unitedproj \\ Button.h 14 1 unitedProj

  • 错误5错误C2660:'MouseListener :: MousePressed':函数未采用4个参数C:\\ Users \\ Gonen \\ unitedProj \\ unitedProj \\ Button.cpp 24 1 unitedProj

前两个用于main中的声明,最后一个用于Button.cpp中的函数。 救命? 当我将鼠标光标放在Button.cpp中的函数上时,我得到:

void MouseListener :: MousePressed(Button&b,int x,int y,bool isLeft)

我只需要这个就可以了,这样我就可以继续前进,让其余的小组成员在他们实现的控件中使用按钮...并继续下一个我需要做的事情:-(

编辑:谢谢您的快速解答。 我试图按照你的要求去做。 现在我得到:

*错误3错误LNK2019:函数__tmainCRTStartup C:\\ Users \\ Gonen \\ unitedProj \\ unitedProj \\ MSVCRTD.lib(crtexe.obj)中引用的未解析的外部符号主要unitedProj

在声明MousePressed的位置未声明Button ,因此无法使用它。 我建议您使用前向声明。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM