Possible Duplicates:
Why copying stringstream is not allowed?
how copy from one stringstream object to another in C++?問題的ostringstream和拷貝構造
編譯T級失敗,Visual C++和GCC產生輸入輸出流模板錯誤。下面是代碼:
#include <sstream>
class T
{
static T copy;
std::ostringstream log;
T() {}
T(const T& t) {log = t.log;}
~T() {copy = *this;}
};
T T::copy;
更改日誌數據成員類型爲字符串,使得它編譯並運行正常。這是一種合法行爲嗎?
OK,這是真的,但我得到了同樣的錯誤,即使空的拷貝構造函數:'T(const的T&T){}' –
@保羅:郵政實際的代碼和錯誤。 – Nawaz
@Nawasz:代碼是在我的問題上面的複製構造函數替換爲:'T(const T&t){}'或'T(const T&t){log << t.log.str();}'或'T(const T&t){log << t.log.rdbuf();}'。我總是得到:_'std :: basic_ios <_Elem,_Traits> :: operator =':沒有虛擬基地聲明的私人成員的可訪問路徑'std :: basic_ios <_Elem,_Traits>'_ –