如何实现一个继承fstream的类
嘿伙计们,当我想创建一个使用 fstream 的名为 Files 的类时,我遇到了问题
#include<iostream>
#include<fstream>
class Files:public fstream {
public:
Files(const char* s,ios_base::openmode mode = ios_base::in | ios_base::out):fstream(s,ios_base::openmode mode = ios_base::in | ios_base::out)
};
有谁知道我应该在构造函数上使用哪些参数?
Hey guys, im having problems when i want to create a class Called Files that uses fstream
#include<iostream>
#include<fstream>
class Files:public fstream {
public:
Files(const char* s,ios_base::openmode mode = ios_base::in | ios_base::out):fstream(s,ios_base::openmode mode = ios_base::in | ios_base::out)
};
Does anyone know which parameters should i use on the constructor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要重复默认参数。您的代码应该如下所示:
也就是说您可能需要考虑使用
Don't repeat the default parameters. Your code should look like this:
That being said you may want to consider using Boost.Iostreams if you want to define your own stream classes. Overriding all the correct methods from the standard streams is a pain.
不要从没有虚拟析构函数的类继承
Don't inherit from classes that doesn't have virtual destructors