首页 > 解决方案 > 不推荐使用隐式声明的 boost::iostreams::mapped_file_source

问题描述

我正在定义一个结构如下:

struct memory_dump {
    filesystem::path path;
    boost::iostreams::mapped_file_source mapped_file;
    memory_dump_type type;
    long long int offset;
};

但是,gcc会生成以下警告:

warning: implicitly-declared ‘boost::iostreams::mapped_file_source& boost::iostreams::mapped_file_source::operator=(const boost::iostreams::mapped_file_source&)’ is deprecated [-Wdeprecated-copy]
   39 | struct memory_dump {
      |        ^~~~~~~~~~~

此警告仅在将我的Boost版本从1.62.0左右升级到1.72.0. 我重新搜索了警告,但我没有找到关于这个特定Boost类的任何信息,为什么会生成警告以及如何修复它。我的目标是存储一个实例,mapped_file_source这样我就可以有效地访问内存映射文件的内容。

标签: c++gccboostmemory-mapped-files

解决方案


你可以在这里看到:https ://en.cppreference.com/w/cpp/language/copy_assignment

如果 T 具有用户声明的析构函数或用户声明的复制构造函数,则不推荐生成隐式定义的复制赋值运算符(C++11 起)。

如您所见,在 boost 1.72 中就是这种情况:

    // Copy Constructor
    mapped_file_source(const mapped_file_source& other);

在第 187 行有这个复制构造函数boost\iostreams\device\mapped_file.hpp


推荐阅读