错误:在"boost::文件系统::p ath::文件名() const() + "/""中与"运算符+"不匹配
error: no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’
我正在使用这个源,但我收到此错误:
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
相关文章:
- 在运算符重载定义中使用成员函数(const错误)
- 不允许运算符 const 参数调用 const 成员函数
- C++概念assignable_from不接受 const&-return 运算符=
- 有人可以用"显式运算符 const GUID_t&() const"来解释成员函数的函数吗?
- 关于重载 -> 运算符中 const 关键字的特定位置的问题
- 类型"int"和"const char [15]"到二进制"运算符<<"的无效操作数^
- 在函数中使用运算符重载,在 c++ 中使用 const 类型输入参数
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 为什么 std::basic_ostream::运算符<<不符合 CONST 资格?
- 在运算符重载中使用带有 const 引用的 friend 函数
- STL按客户"<"运算符对向量进行排序。为什么要将"<"运算符定义为 const?
- 如何在 std::map<const int、int> C++ 中重载插入运算符>>?
- 错误:二进制">>":未找到采用类型为"const char [1] 的右操作数的运算符
- 为什么重载运算符>在参数声明 const 时不起作用?
- 我收到一个错误无效的操作数,类型为 const char [42] 和二进制"运算符+"的双倍数
- 错误:C2679 二进制"==":未找到采用类型 'const std::string' 的右侧操作数的运算符(或者没有可接受的转换)
- 重载 * 运算符时不使用 const 的影响
- Const 仍然允许在运算符函数 c++ 下进行更改
- const std::function 包装一个非 const 运算符() / 可变 lambda
- 成员函数中的Const运算符(为什么可以分为两个不同的部分)