【问题标题】:Why does my call to 'wxGetTranslation' result in the compiler error "ambiguous call to overloaded function"?为什么我对“wxGetTranslation”的调用会导致编译器错误“对重载函数的模糊调用”?
【发布时间】:2011-09-19 05:14:24
【问题描述】:
c:\wxwidgets-2.8.11\include\wx\filename.h(497): error C2668: 'wxGetTranslation' : ambiguous call to overloaded function
          c:\bitcoin\src\util.h(191): could be 'const char *wxGetTranslation(const char *)'
          c:\wxwidgets-2.8.11\include\wx\intl.h(579): or       'const wxChar *wxGetTranslation(const wxChar *,const wxChar *)'
          while trying to match the argument list '(const char [14])'
wxString GetHumanReadableSize(
    const wxString &nullsize = wxGetTranslation(wxT("Not available")),
    int precision = 1) const;

我完全不明白这是多么模棱两可?一个需要 1 个 arg,另一个需要 2 个。该文件使用 1 个 arg 调用它。

【问题讨论】:

    标签: c++ wxwidgets bitcoin


    【解决方案1】:

    这是因为其他函数有第二个参数作为默认参数See here我模拟了同样的效果。不幸的是,编译器没有在错误消息中显示默认参数:

    //intl.h
    const wxChar *wxGetTranslation(const wxChar *c1, const wxChar *c2 = <something>);
    

    更准确地说,

    void foo (const char* c1);  // 1st
    void foo (const char* c1, const char *c2 = 0);  // 2nd
    

    当您尝试调用第一个版本时会产生歧义,因为第二个版本也是一个同样出色的候选者。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多