错误 C2660:'MouseListener::MousePressed':函数不接受 4 个参数

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

本文关键字:参数 不接受 MouseListener C2660 错误 MousePressed 函数      更新时间:2023-10-16

im在C 伪图形按钮上工作。我使用观察者模式。

in button.cpp:

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

您可以看到Mousepressed功能会收到4个参数,但我得到:

函数不接受4个参数

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;
.
.
.

主要:

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:语法错误:标识符'按钮'c: users gonen gonen unitedproj unitedproj button.h 14 1 unitedproj

  • 错误4错误c2061:语法错误:标识符'按钮'c: users gonen gonen unitedproj unitedproj button.h 14 1 unitedproj

  • 错误5错误C2660:'Mouselistener :: Mousepressed':function不接受4个参数C: Users Gonen Gonen United Proj UnitedProj United Proj button.cpp 24 1 UnitedProj >

当前两个用于主张时,最后一个是在button.cpp中使用函数。帮助?当我用鼠标光标站立在button中的函数上时。cpp我得到:

void mouselistener :: mousepressed(button&amp; b,int x,int y,bool isleft)

我只需要它来工作,以便我可以继续前进,让小组成员使用他们实现的控件中的按钮...然后继续进行下一个我需要做的: - (

编辑:谢谢您的快速答案。我试图做你问的事情。现在我得到:

*错误3错误lnk2019:函数中引用的未解决的外部符号main main c: users gonen gonen gonen unitedproj unitedproj msvcrtd.lib(crtexe.obj)

Button在声明MousePressed的点未声明,因此不能使用它。我建议您应该使用远期声明。

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;
.
.
.