如果我實例化一個mapped_file_source(升壓1.46.1)用窄字符串如下面的我沒有一個問題:使用boost ::輸入輸出流:: mapped_file_source寬字符串
boost::iostreams::mapped_file_source m_file_("testfile.txt");
但是,如果我嘗試使用寬字符串:
boost::iostreams::mapped_file_source m_file_(L"testfile.txt");
我得到VC2010 SP1以下編譯器錯誤:
P:\libs\boost_1_46_1\boost/iostreams/device/mapped_file.hpp(128): error C2248: 'boost::iostreams::detail::path::path' : cannot access private member declared in class 'boost::iostreams::detail::path'
P:\libs\boost_1_46_1\boost/iostreams/detail/path.hpp(111) : see declaration of 'boost::iostreams::detail::path::path'>
P:\libs\boost_1_46_1\boost/iostreams/detail/path.hpp(37) : see declaration of 'boost::iostreams::detail::path'
如果我不是試圖通過構造一個boost ::文件系統::路徑我得到以下錯誤:
P:\libs\boost_1_46_1\boost/iostreams/device/mapped_file.hpp(128): error C2664: 'boost::iostreams::detail::path::path(const std::string &)' : cannot convert parameter 1 from 'const boost::filesystem3::path' to 'const std::string &'
Reason: cannot convert from 'const boost::filesystem3::path' to 'const std::string'
我覺得我失去了一些東西很明顯,但我只是手忙腳亂試圖弄清楚編譯器試圖告訴我什麼,但我只是迷了路。那掌心到額頭時刻就是沒有發生..我做錯了什麼?
在mapped_file.hpp定義的構造函數如下所示:
// Constructor taking a parameters object
template<typename Path>
explicit mapped_file_source(const basic_mapped_file_params<Path>& p);
的basic_mapped_file_params類的構造是這樣的:
// Construction from a Path
explicit basic_mapped_file_params(const Path& p) : path(p) { }
// Construction from a path of a different type
template<typename PathT>
explicit basic_mapped_file_params(const PathT& p) : path(p) { }
當模板類的定義爲:
// This template allows Boost.Filesystem paths to be specified when creating or
// reopening a memory mapped file, without creating a dependence on
// Boost.Filesystem. Possible values of Path include std::string,
// boost::filesystem::path, boost::filesystem::wpath,
// and boost::iostreams::detail::path (used to store either a std::string or a
// std::wstring).
template<typename Path>
struct basic_mapped_file_params
: detail::mapped_file_params_base
{
標題中有一些額外的幫助:
// For wide paths, instantiate basic_mapped_file_params
// with boost::filesystem::wpath
如果我採取這種做法:
boost::iostreams::basic_mapped_file_params<boost::filesystem::wpath> _tmp(L"test.txt");
boost::iostreams::mapped_file_source m_file_(_tmp);
我得到上述同樣的C2664錯誤..
我知道的編譯器告訴我是什麼問題,但看着頭源和評論導致我相信,我試圖完成的是支持的,這只是我的方法是不正確的。我誤解了頭文件告訴我什麼?我知道在這裏某處可能有關於模板實例化和顯式/隱式轉換的很好的教訓。
有趣的是,升級我的提振安裝到1.47.0似乎清理C2664錯誤,但我仍然獲取有關訪問私有成員C2248錯誤。
我加入的問題一些額外的信息。我理解編譯器告訴我什麼,我只是不明白爲什麼,從mapped_file.hpp頭文件的源頭 –
@ C.Trauma:如果這是頭文件的樣子,那麼文檔就過時了。我發現的文檔頁是從1.47.0。 –
滾動到文檔頁面底部顯示「2008年2月2日修訂」,因此很可能它們已過期。 –