How to return an fstream (C++0x)

前端 未结 3 471
一整个雨季
一整个雨季 2020-12-11 04:17

I think I\'ll get right into it and start with the code:

#include 
#include 
#include 

class test : public std:         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 04:56

    The problem is with this:

    test(test&& old) {};
    

    This lets you construct a new test from an rvalue test, yes, but it says nothing about your base, which is simply being default constructed (no open file). What you want is this:

    test(test&& old) : std::ofstream(std::move(old)) {};
    

    Which will move the stream from old into the base.

提交回复
热议问题