我有以下使用boost文件系统的类,但在编译时遇到了问题。
/// 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 传递给类的构造函数?