在构造函数中,没有匹配的函数调用 [英] in constructor, no matching function call to

查看:268
本文介绍了在构造函数中,没有匹配的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  gridlist.h:在构造函数GridList :: GridList(WINDOW *,int,int,int, int; int)':
gridlist.h:11:47:error:没有匹配的函数调用'Window :: Window()'
gridlist.h:11:47: :
window.h:13:3:note:Window :: Window(WINDOW *,int,int,int,int,int)

我的代码

  GridList(WINDOW * parent = stdscr,int colors = MAG_WHITE ,int height = GRIDLIST_HEIGHT,int width = GRIDLIST_WIDTH,int y = 0,int x = 0)
:Window(parent,colors,height,width,y,x){
this-> m_buttonCount = -1;
m_maxButtonsPerRow =((GRIDLIST_WIDTH)/(BUTTON_WIDTH + BUTTON_SPACE_BETWEEN));
this-> m_buttons = new Button * [50];
refresh();
}

我有点不确定是什么试图告诉我,我做错了。我传递正确的变量类型到类和正确的参数数量。但它说我试图调用 Window :: Window()没有参数。先感谢任何帮助。



类Button编译得很好,几乎完全一样。

 按钮(WINDOW * parent = 0,int colors = STD_SCR,int height = BUTTON_WIDTH,int width = BUTTON_HEIGHT,int y = 0,int x = 0)
:Window parent,colors,height,width,y,x){
this-> refresh();
}


解决方案

> GridList 类有一个 Window 类型的成员变量。由于所有成员都是(默认情况下未指定)在之前初始化构造函数的主体,您的实际情况与此类似:

  GridList :: GridList(...)
:Window(...),m_tendMenu()//< - 这里是你看不到的问题

您的成员变量正在被初始化,但您的 Window 默认构造函数,因此的问题。要修复它,在成员初始化器中初始化成员变量:

  GridList :: GridList(...)
:Window(...),m_tendMenu(更多...),//其他成员在这里会很好

您的 Button 类的工作原因是因为它没有 Window 类型的成员,因此,当它不能被初始化时,没有什么是默认初始化。


My error

gridlist.h: In constructor ‘GridList::GridList(WINDOW*, int, int, int, int, int)’:
gridlist.h:11:47: error: no matching function for call to ‘Window::Window()’
gridlist.h:11:47: note: candidates are:
window.h:13:3: note: Window::Window(WINDOW*, int, int, int, int, int)

My code

GridList(WINDOW *parent = stdscr, int colors = MAG_WHITE, int height = GRIDLIST_HEIGHT, int width = GRIDLIST_WIDTH, int y = 0, int x = 0) 
: Window(parent, colors, height, width, y, x) {
    this->m_buttonCount = -1;
    m_maxButtonsPerRow = ((GRIDLIST_WIDTH)/(BUTTON_WIDTH+BUTTON_SPACE_BETWEEN));
    this->m_buttons = new Button *[50];
    refresh();
}

I am a little unsure of what exactly it is trying to tell me and what I am doing wrong. I am passing the correct variable types to the class and the correct number of parameters. However it says I am trying to call Window::Window() with no parameters. Thanks in advance for any help.

The class Button compiles just fine, and is almost exactly the same.

Button(WINDOW *parent = 0, int colors = STD_SCR, int height = BUTTON_WIDTH, int width = BUTTON_HEIGHT, int y = 0, int x = 0) 
: Window(parent, colors, height, width, y, x) {
            this->refresh();
        }

解决方案

Your GridList class has a member variable of type Window. Since all members are (default if unspecified) initialized before the body of the constructor, yours looks similar to this in reality:

GridList::GridList (...)
 : Window(...), m_tendMenu() //<--here's the problem you can't see

Your member variable is being default initialized, but your Window class has no default constructor, hence the problem. To fix it, initialize your member variable in your member initializers:

GridList::GridList (...)
 : Window(...), m_tendMenu(more ...), //other members would be good here, too

The reason your Button class works is because it doesn't have a member of type Window, and thus, nothing being default-initialized when it can't be.

这篇关于在构造函数中,没有匹配的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆