我有使用提高文件系统下面的类,但在编译时遇到的问题。
/// tfs.h file:
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
using namespace boost;
using namespace std;
class OSxFS
{
public:
OSxFS(string _folderPath)
{
mFolderPath(_folderPath);
}
string ShowStatus()
{
try
{
filesystem::file_status folderStatus = filesystem::status(mFolderPath);
cout<<"Folder status: "<<filesystem::is_directory(folderStatus)<<endl;
}
catch(filesystem::filesystem_error &e)
{
cerr<<"Error! Message: "<<e.what()<<endl;
}
}
private:
filesystem::path mFolderPath;
}
在m.cpp文件,我用下面的代码来调用OSxFS类:
///m.cpp file
#include "tfs.h"
#include <iostream>
#include <string>
using namespace std;
using namespace boost;
int main()
{
string p = "~/Desktop/";
OSxFS folderX(p);
folderX.ShowStatus();
cout<<"Thank you!"<<endl;
return 0;
}
但是,我得到了错误信息,当我在Xcode编译它们用g ++:
In file included from m.cpp:1:
tfs.h: In constructor ‘OSxFS::OSxFS(std::string)’:
tfs.h:13: error: no match for call to ‘(boost::filesystem::path) (std::string&)’
m.cpp: At global scope:
m.cpp:5: error: expected unqualified-id before ‘using’
如果我实现一个单一的main.cpp类OSxFS的功能ShowStatus(),它的工作原理。 所以,我想这个问题是关于如何将字符串变量_folderPath传递给类的构造函数?