C++ 使用本机()boost路径访问器
我得到这个错误:C++ 使用本机()boost路径访问器,c++,gcc,boost,boost-filesystem,C++,Gcc,Boost,Boost Filesystem,我得到这个错误: 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: 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>&}’
我更改了第一个if,以便按照这里的建议更干净,但他们也告诉我使用native()路径访问。然后。。。你为什么不呢?:)
到目前为止,这可能是有道理的
- 为
it->path()/s
- 阅读
代码表明您正在尝试递归地遍历文件系统树。你看过boost::recursive\u directory\u迭代器了吗
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;
}
if(recursively && !loadDirectory((it->path() / s).native(), npc, recursively))