c++ - 错误 : no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’

标签 c++ gcc boost

我正在使用此源,但出现此错误:

  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 的非传统运算符重载非常好的罕见情况:)

关于c++ - 错误 : no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20937308/

相关文章:

c++ - 为什么 C/C++ 代码可在不同的编译器上编译很重要?

c++ - 链接 : fatal error LNK1104: cannot open file 'boost_program_options.lib'

c++ - 向用户显示异常调试信息

c++ - 如何将 C++ 数字格式设置为一定的精度?

c++ - Xcode 中的 C\C++ 构建链接器错误

c++ - 用 bool 逻辑替换 IF 语句(随机条件) - 执行时间是否相同?

c++ - 我可以在 SDL 窗口外跟踪我的鼠标位置吗?

c - ARM 中 uint8_t 变量上的 LDR 行为?

c++ - 为什么 gcc 4.7.0 在这段代码上给我一个段错误,而在线 ideone(gcc 4.5.1) 却没有?

c++ - boost 目录迭代器错误 : no match for operator! =