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
Post a Comment