错误:'boost::filesystem::path::filename() const() + "/"' 中的'operator+' 不匹配
Posted
技术标签:
【中文标题】错误:\'boost::filesystem::path::filename() const() + "/"\' 中的\'operator+\' 不匹配【英文标题】:error: no match for ‘operator+’ in ‘boost::filesystem::path::filename() const() + "/"’错误:'boost::filesystem::path::filename() const() + "/"' 中的'operator+' 不匹配 【发布时间】:2014-01-05 18:17:55 【问题描述】:我正在使用此来源,但出现此错误:
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;
【问题讨论】:
【参考方案1】:你想要
if(recursively && !loadDirectory(it->path() / s, npc, recursively))
return false;
它更短、更优雅、针对分配进行了优化并且独立于平台!
IMO 这是一种罕见的情况,非传统运算符重载确实很好地在 C++ 中实现“即时”直观的 eDSL :)
【讨论】:
@user3084450 要转换为字符串,请使用已记录的路径访问器之一:native()
、generic_string()
等boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/…以上是关于错误:'boost::filesystem::path::filename() const() + "/"' 中的'operator+' 不匹配的主要内容,如果未能解决你的问题,请参考以下文章