Creating object with constant parameters from stream

前端 未结 4 2066
我在风中等你
我在风中等你 2021-01-18 05:02

let us assume I have a class with

#include 
using namespace std;

class Test{
    public:
        friend istream& operator >> (istr         


        
4条回答
  •  别那么骄傲
    2021-01-18 06:03

    You can't. Streams are something you read from, they are not factories or something like that.

    You have several choices, though:

    • Read from the stream to a non-const, and then use that to initialize your const object

    • You can make dummy non-const, initialize your object as unread, and then read into dummy; then you can pass outside only const& to dummy

提交回复
热议问题