我收到此错误:
luascript.cpp: In member function ‘bool LuaInterface::loadDirectory(const string&, Npc*, bool)’:
luascript.cpp:744:69: error: no matching function for call to ‘LuaInterface::loadDirectory(boost::filesystem3::path, Npc*&, bool&)’
luascript.cpp:744:69: note: candidate is:
luascript.cpp:736:6: note: bool LuaInterface::loadDirectory(const string&, Npc*, bool)
luascript.cpp:736:6: note: no known conversion for argument 1 from ‘boost::filesystem3::path’ to ‘const string& {aka const std::basic_string<char>&}’
这段代码:
bool LuaInterface::loadDirectory(const std::string& dir, Npc* npc/* = NULL*/, bool recursively/* = false*/)
{
StringVec files;
for(boost::filesystem::directory_iterator it(dir), end; it != end; ++it)
{
std::string s = it->path().filename().string();
if(boost::filesystem::is_directory(it->status()))
{
if(recursively && !loadDirectory(it->path() / s, npc, recursively))
return false;
}
else if((s.size() > 4 ? s.substr(s.size() - 4) : "") == ".lua")
files.push_back(s);
}
std::sort(files.begin(), files.end());
for(StringVec::iterator it = files.begin(); it != files.end(); ++it)
{
if(!loadFile(dir + (*it), npc))
return false;
}
return true;
}
我改变了第一个如果要像这里建议的更干净,但他们也告诉我使用native()路径加速器。
答案 0 :(得分:3)
然后......你为什么不呢? :)
if(recursively && !loadDirectory((it->path() / s).native(), npc, recursively))
到目前为止,
可能有意义it->path() / s
boost::recursive_directory_iterator
吗?