没有匹配的调用函数(需要引用指针而不是指针)

发布于 2024-10-15 02:21:00 字数 1179 浏览 2 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

書生途 2024-10-22 02:21:00

问题不在于第一个参数;这是第二个。您正在传递一个临时 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 a const reference, but it cannot convert it to a reference. You need to make ShowComboDialog take a const reference as its second parameter.

十级心震 2024-10-22 02:21:00

您的 ShowComboDialog 通过非常量引用获取 wxString,并且您尝试将临时对象作为参数传递给此参数。您只能将 const 引用绑定到临时对象。

您需要更改 ShowComboDialog 以通过值 (wxString) 或 const 引用 (const wxString&) 获取其第二个参数,或者您需要为您在调用函数时创建的 wxString 创建一个变量,然后传递(引用)该变量。

Your ShowComboDialog takes a wxString 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 the wxString that you create when you call the function and then pass (a reference to) that variable instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文