1
我期待在使用boost ::系列化,並嘗試使用上http://www.ocoudert.com給出一個字符串幫手它具有界面引用一個const char *,錯誤C2664:
SerializeCStringHelper(char*& s) : s_(s) {}
SerializeCStringHelper(const char*& s) : s_(const_cast<char*&>(s)) {}
我嘗試使用這個助手在下面的代碼(getName()返回一個的std :: string)
bool MyUtilities::saveSerialLibraryToFile(const string& fileName, const MyLibrary& lib)
{
bool saved = false;
ofstream out(fileName, ios::app);
if(out.is_open())
{
boost::archive::text_oarchive ar(out);
const char* str = lib.getName().c_str();
SerializeCStringHelper helper(str);
// SerializeCStringHelper helper(lib.getName().c_str());
ar & helper;
saved=true;
}
return saved;
}
它編譯罰款,但現在如果我更換了與註釋掉的代碼爲const char *海峽和輔助線,我得到的編譯錯誤C2664:無法將參數1從'const char *'轉換爲'char * &'
我的問題是,爲什麼單行,不同於兩個單獨的行?
輝煌,謝謝 –
如果答案有用,您可以接受;) – Borgleader