ifstream作爲函數的參數要加&

void foo(ifstream ifs) {} // 編譯出錯

void foo(ifstream& ifs) {} // 編譯成功

原因:stream不能被複制

實現方法:

Make the copy constructor and assignment operator private (like inthe "ios" example - remember members are private by default if youdeclare your class with "class"). If you write any constructors you
don't get the implicit default constructor, so make sure you write at least one accessible constructor or you won't be able to create any objects of this class.

Regards
Buster

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章