错误:在"boost::文件系统::p ath::文件名() const() + "/""中与"运算符+"不匹配

error: no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’

本文关键字:const 运算符 不匹配 中与 文件名 boost 文件系统 ath 错误      更新时间:2023-10-16

我正在使用这个源,但我收到此错误:

  In file included from /usr/include/boost/filesystem.hpp:15:0,
[LIST=1]
                 from luascript.cpp:21:
/usr/include/boost/filesystem/config.hpp:16:5: error: #error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’:
luascript.cpp:745:61: error: no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’
make[1]: *** [luascript.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/home/dv/src.DEB'
make: *** [all] Error 2
[/LIST]

使用这段代码:

if(boost::filesystem::is_directory(it->status()))
        {
            if(recursively && !loadDirectory(it->path().filename() + "/" + s, npc, recursively))
                return false;
        }

你想要

if(recursively && !loadDirectory(it->path() / s, npc, recursively))
            return false;

它更短,更优雅,针对分配进行了优化,并且独立于平台

IMO 这是非传统运算符重载在极少数情况下非常有效地实现C++ :)"即时"直观的 eDSL

相关文章: