无法编译代码,因为它已在 C++11 中弃用
Can not compile the code because it is deprecated in C++11
我有一个使用 ns-3 编译的代码,但是当我尝试编译它们时遇到了一些问题。我认为原因可能是某些函数在 C++11 中被弃用。但是我不知道如何修改代码。
这是我认为应该修改的代码:
m_sendBuffer.erase(
std::remove_if(
m_sendBuffer.begin(), m_sendBuffer.end(),
std::bind2nd(std::ptr_fun(DsrSendBuffer::IsEqual), dst)
),
m_sendBuffer.end()
);
这是错误:
../src/dsr/model/dsr-rsendbuff.cc:102:55: error: 'ptr_fun<ns3::dsr::DsrSendBuffEntry, ns3::Ipv4Address, bool>' is deprecated [-Werror,-Wdeprecated-declarations]
std::bind (std::ptr_fun (DsrSendBuffer::IsEqual), dst)), m_sendBuffer.end ());
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1115:1: note: 'ptr_fun<ns3::dsr::DsrSendBuffEntry, ns3::Ipv4Address, bool>' has been explicitly marked deprecated here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
似乎他们确实使用了已弃用的 API,但您仍然可以通过允许将弃用警告视为警告来编译它。将此添加到编译器选项中:
-Wno-error=deprecated-declarations
如果您想升级代码,可以改为执行以下 lambda:
m_sendBuffer.erase(
std::remove_if(
m_sendBuffer.begin(), m_sendBuffer.end(),
[&dst](auto const& buf) { return DsrSendBuffer::IsEqual(buf, dst); }
),
m_sendBuffer.end()
);
您可以从ns-3 @ gitlab克隆新版本的ns-3
。
std::ptr_fun
和std::bind2nd
的使用已于 2019 年 8 月 25 日删除。
相关文章:
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 编译器不会使用 -std=c++11 编译智能指针
- 如何在 C++11 编译时构建具有递增值的整数成员的结构序列
- 无法用"-std=c++11"编译《你好世界》
- 为 freebsd 11 编译 gcc4.8.5 时出错: 错误: 未知类型名称 'choke'
- 如何使用Codelite 11.0.0编译静态库
- mingw:使用 -std=c++11 编译时找不到函数
- 如何在 ubuntu 12.10 中隐藏 g++ c++11 编译警告
- 用C++14编译器而不是C++11编译时,我的性能会提高吗
- Qmake 不使用 stdc++11 编译标志
- 为什么 std::stoi 和 std::array 不能使用 g++ c++11 编译
- Makefile C++11-编译为静态库
- 代码块中的C++11编译问题
- gcc在c++11编译中给出垃圾
- 如何告诉一个库是使用C++11编译的
- 使用makefile和c++11编译时出错
- c++ 11编译时组合两个字符串的最简单方法
- 用Visual Studio 11编译的可执行文件有什么特别之处,导致这些可执行文件不能在Windows XP上执行?
- c++ 11编译时调用printf的格式字符串字面值构造
- 如何在Xcode 8下用c++ 11编译一个项目