没有匹配的调用函数(需要引用指针而不是指针)
我从 xcode (3.2.4)/gcc(4.0) 收到错误:
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp: In member function 'void DeviceToolBar::ShowInputDialog()':
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp:817: error: no matching function for call to 'DeviceToolBar::ShowComboDialog(wxChoice*&, wxString)'
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.h:74: note: candidates are: void DeviceToolBar::ShowComboDialog(wxChoice*, wxString&)
所以看起来它需要对 ShowComboDialog 中的指针的引用,但我不知道为什么,因为签名显然是普通指针。此外,如果它期望对指针的引用,那么我调用它的方式应该可以工作。 这是第一个错误,之前没有任何特殊警告。
此外,它在 MSVC 2008 Express 中编译。 请给我一个线索。
//in the class def
//(only relevant portions included
class DeviceToolBar:public ToolBar {
public:
DeviceToolBar();
virtual ~DeviceToolBar();
void ShowInputDialog();
private:
void ShowComboDialog(wxChoice *combo, wxString &title);
wxChoice *mInput;
};
//in the cpp file
void DeviceToolBar::ShowInputDialog()
{
ShowComboDialog(mInput, wxString(_("Select Input Device")));
}
void DeviceToolBar::ShowComboDialog(wxChoice *combo, wxString &title)
{
//...
}
I get the error from xcode (3.2.4)/gcc(4.0):
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp: In member function 'void DeviceToolBar::ShowInputDialog()':
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.cpp:817: error: no matching function for call to 'DeviceToolBar::ShowComboDialog(wxChoice*&, wxString)'
/Users/admin/scm/audacity/mac/../src/toolbars/DeviceToolBar.h:74: note: candidates are: void DeviceToolBar::ShowComboDialog(wxChoice*, wxString&)
So it looks like it expects a reference to a pointer in ShowComboDialog, but I don't know why as the signatures are clearly normal pointers. Furthermore if it was expecting a reference to a pointer the way I am calling it should work.
This is the first error, and there are no special warnings before it.
Also, this compiles in MSVC 2008 express.
Please give me a clue.
//in the class def
//(only relevant portions included
class DeviceToolBar:public ToolBar {
public:
DeviceToolBar();
virtual ~DeviceToolBar();
void ShowInputDialog();
private:
void ShowComboDialog(wxChoice *combo, wxString &title);
wxChoice *mInput;
};
//in the cpp file
void DeviceToolBar::ShowInputDialog()
{
ShowComboDialog(mInput, wxString(_("Select Input Device")));
}
void DeviceToolBar::ShowComboDialog(wxChoice *combo, wxString &title)
{
//...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不在于第一个参数;这是第二个。您正在传递一个临时
wxString
,但该函数需要一个引用。 C++ 会自动将临时变量转换为 const 引用,但无法将其转换为引用。您需要使ShowComboDialog
将 const 引用作为其第二个参数。The problem is not the first parameter; its the second. You're passing in a temporary
wxString
, but the function is expecting a reference. C++ will automatically convert a temporary to aconst
reference, but it cannot convert it to a reference. You need to makeShowComboDialog
take a const reference as its second parameter.您的
ShowComboDialog
通过非常量引用获取wxString
,并且您尝试将临时对象作为参数传递给此参数。您只能将 const 引用绑定到临时对象。您需要更改 ShowComboDialog 以通过值 (
wxString
) 或 const 引用 (const wxString&
) 获取其第二个参数,或者您需要为您在调用函数时创建的wxString
创建一个变量,然后传递(引用)该变量。Your
ShowComboDialog
takes awxString
by non-const reference and you are trying to pass a temporary object as an argument to this parameter. You can only bind const references to temporary objects.You either need to change
ShowComboDialog
to take its second argument either by value (wxString
) or by const reference (const wxString&
) or you need to create a variable for thewxString
that you create when you call the function and then pass (a reference to) that variable instead.