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

前端 未结 3 438
一整个雨季
一整个雨季 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.

    0 讨论(0)
  • 2020-12-11 04:58

    I'm going to answer my own question here:

    In the GCC C++0x Library Features page, have a look at item 27.9, which reads:

    27.9 - File-based streams - Partial - Missing move and swap operations

    I guess that's probably the issue I'm having with gcc.

    0 讨论(0)
  • 2020-12-11 05:11

    Does the caller need to know that you are returning an ofstream, or would it make more sense to return a streambuf, and let the caller wrap it inside a stream?

    0 讨论(0)
提交回复
热议问题