简体   繁体   English

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

[英]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) un‌​itedProj *错误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.

相关问题 C ++错误C2660:函数没有3个参数 - C++ Error C2660: Function does not take 3 arguments 奇怪的错误c2660“函数不带1个参数” - Strange error c2660 “function does not take 1 arguments” 错误C2660:函数没有2个参数C ++ - Error C2660: function does not take 2 arguments C++ 错误C2660:&#39;Aba :: f&#39;:函数未使用0个参数 - error C2660: 'Aba::f' : function does not take 0 arguments 简短版本:错误14错误C2660:“ Player :: addSpell”:函数未采用1个参数 - Short version: Error 14 error C2660: 'Player::addSpell' : function does not take 1 arguments 错误 C2660: 'std::allocator<char> ::allocate': function 不占用 2 arguments</char> - error C2660: 'std::allocator<char>::allocate': function does not take 2 arguments 错误 C2660: 'std::pair<a,b> ::pair': function 不带 2 arguments</a,b> - error C2660: 'std::pair<a,b>::pair': function does not take 2 arguments C ++中的特征库给出错误C2660:&#39;Eigen :: MatrixBase <Derived> :: eigenvalues&#39;:函数不带2个参数 - eigen library in C++ gives error C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' : function does not take 2 arguments 如何解决“C2660 &#39;SWidget::Construct&#39;:函数不接受 1 个参数”? - How to resolve "C2660 'SWidget::Construct': function does not take 1 arguments"? 尝试在 windows 10 上安装 node-ffi 会出现错误:error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments - trying to install node-ffi on windows 10 gives error: error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM