【问题标题】:wxWidgets deprecated constructorwxWidgets 已弃用的构造函数
【发布时间】:2017-05-02 08:42:54
【问题描述】:

我正在尝试使用 wxWidgets 3.0 库编译以下代码:

foo.h

#ifdef __GNUC__
  #include <wx/version.h>

  #if wxMAJOR_VERSION >= 3
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wdeprecated-declarations" //< I'm trying to disable warning
  #endif // wxMAJOR_VERSION >= 3

#endif // __GNUC__

#ifdef HAVE_VARIADIC_MACROS
  #undef HAVE_VARIADIC_MACROS //< this macro redefines in wx.h
#endif // HAVE_VARIADIC_MACROS

#include <wx/wx.h> //< deprecated constructor defined here

#ifdef __GNUC__
  #pragma GCC diagnostic pop
#endif // __GNUC__

foo.cpp

#include "foo.h"
....
some_menu = new wxMenuItem( ... ); //< deprecated constructor

文件wx/menuitem.h中定义的构造函数 代码:

#if WXWIN_COMPATIBILITY_2_8 //< defined
    // compatibility only, don't use in new code
    wxDEPRECATED_CONSTRUCTOR(
    wxMenuItem(wxMenu *parentMenu,
               int id,
               const wxString& text,
               const wxString& help,
               bool isCheckable,
               wxMenu *subMenu = NULL)
    );
#endif

使用 gcc 5.4.0、Ubuntu 16.04 x86_64 编译:

    g++ -o foo.os -c -I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -g3 -Wall -Werror
...
foo.cpp:83:109: error: 'wxMenuItem::wxMenuItem(...)' is deprecated [-Werror=deprecated-declarations]

我该如何解决?

【问题讨论】:

    标签: gcc g++ wxwidgets gcc5


    【解决方案1】:

    显而易见且最好的解决方案是停止使用已弃用的 ctor,这很简单,为什么不呢?

    否则,我认为(但我没有测试它)你也可以让它与#pragmas 一起工作,但你需要使用这个ctor 将它们放在你的代码周围,因为这是生成警告的地方,而不是声明周围。

    最后,为了完整起见,您还可以删除 -Werror 并接受警告,但这当然不是最佳选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-28
      • 2021-09-10
      • 2017-12-04
      • 1970-01-01
      • 2015-07-17
      • 1970-01-01
      • 2011-11-07
      • 2020-12-29
      相关资源
      最近更新 更多