C ++ - how to reinitialize an object repeatedly?

I am trying to implement this logic in C ++:

Object obj(args);
while (obj.isOK()) {
    obj = obj.next();
}

But I cannot use this exact code because it Objectinherits boost::noncopyable, therefore it does not have an assignment operator. I can add methods and constructors to Object(but not make it copyable), however I would prefer not to. Other issues include manually destroying and placing the new one as a solution, which I could make if I create a new constructor for Object, but again, preferably, I don’t need a new constructor, and it still seems like a rather unpleasant solution. What are my alternatives?

+4
source share
2

Object::next Object . Object , Object::next. .

+3

Object::next? Object, Object:

Object& operator=(Object&& obj)
{
    //move its iternal state to this and then
    return *this;
}

, .

-1

Source: https://habr.com/ru/post/1614921/


All Articles