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
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
相关文章推荐
- ifstream作为函数的参数要加&
- ifstream 作为函数参数 需要加&
- C++ * a和*&a作为函数的参数时有什么区别
- Python3学习(一)-基础、数据类型、变量、字符串和编码、list&tuple、if、for、while、dict、set、函数与参数
- ”引用 & 指针“ -- 作为函数的参数和返回值小结
- 字符串使用&&引用对象作为函数参数
- C++ 中作为函数参数的&
- 巩固:数组作为函数参数& 指针作为函数参数的用法
- ifstream& operator>>函数无法获取空行和peek函数的用法
- C# 引用类型作为函数参数时
- C语言中实参和形参问题&&函数使用数组作为参数的问题
- ifstream作为函数的参数要加&
- 对象作为函数参数时调用拷贝构造函数、引用做函数参数时只是传递地址
- static函数 函数调用缺少参数列表;请使用“&XXX”创建指向成员的指针;类的static成员函数
- “作为函数参数的二维数组”即“怎么给函数传二维数组的指针”
- 将函数或过程作为参数进行传递实例
- c++将引用或者是指针作为函数参数实现实参的运算
- C++的基础知识(十一)--数组做函数参数、数组名a与&a区别、数组名a的"数据类型"
- 指针的引用作为函数参数有啥用?
- C语言二维数组作为函数的参数