您的位置:首页 > 其它

ifstream作为函数的参数要加&

2011-03-03 11:39 239 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: