开发者

how to implement a class that inherits form fstream

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?


Don't repeat the default parameters. Your code should look like this:

#include<iostream>
#include<fstream>

class Files : public std::fstream {
    public:
       Files(const char* s, 
             std::ios_base::openmode mode = ios_base::in | ios_base::out)
       :std::fstream(s, mode)
       {}
};

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜