How can I override an C++ standard-library class function?

后端 未结 4 2057
长情又很酷
长情又很酷 2021-02-15 17:52

How can I override a C++ standard-library class function? In my application, I use ofstream objects in many different places of code. And now I want to open files i

4条回答
  •  名媛妹妹
    2021-02-15 18:47

    #include 
    #include 
    
    class gstream: public std::ofstream
    {
    
    void open(const std::string& filename, ios_base::openmode mode,int stuff)
            {
                    //put stuff here
    
            }
    };
    
    int main() {
    
            gstream test;
    //io stuff
    return 0;
    }
    

    seems to work here.

提交回复
热议问题