我有一個成員是std::ofstream fBinaryFile
和爲什麼在傳遞std :: ofstream作爲參數時使用「刪除」函數?
void setFile(std::ofstream& pBinaryFile)
{
fBinaryFile = pBinaryFile;
}
輸出:
Data.h:86:16: error: use of deleted function ‘std::basic_ofstream<char>& std::basic_ofstream<char>::operator=(const
std::basic_ofstream<char>&)’
fBinaryFile = pBinaryFile;
^
我瞭解,副本std::ofstream
是不允許的,也許我失去了一些東西。有可能將pBinaryFile
的內容保存在fBinaryfile
?
究竟是你想達到什麼目的?爲什麼你需要將'ofstream'複製到一個局部變量? – Petr
您無法複製流,就像那樣簡單。您只能擁有對流的引用(或指針)。您嘗試解決的原始問題是什麼?你的用例是什麼? –
儘管你可以使用引用或指針。 –