c++ - Unique pointer to stream -


#include <memory> #include <istream>  typedef std::unique_ptr<std::istream> mytype;  class myclass{      mytype mystream; public:      myclass(mytype a_stream){         mystream = std::move(a_stream); //compiler error     }  }; 

why i'm not allowed move newly created stream? far know, streams not copyable, movable. miss something? unique pointer fits non-copyable objects, @ least theorically.

compiler error

 no match 'operator=' 

the argument constructor by-value -- have make by-reference. by-value object needs copied when use constructor. ok, use unique_ptr, still copied can moved.

so, try this:

myclass(mytype &a_stream){     mystream = std::move(a_stream); //compiler error } 

or maybe even

myclass(mytype &&a_stream){     mystream = std::move(a_stream); //compiler error } 

this by-reference , no copy @ place using occur.

although, find strange error @ place of move, may wrong.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -