Function dual to std::move?

后端 未结 3 790
刺人心
刺人心 2020-12-21 09:58

Let\'s assume I have a class with only one constructor:

class T {
 public:
  T(BigClass&& big) : big(std::move(big)) {}
  ...

  SomeBigClass
};
         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-21 10:37

    Why can't you just copy the BigClass object?

    void foo(const BigClass& big) {
      while (...) {
        T t{ BigClass(big) };
        ...
      }
    }
    

    This makes a temporary BigClass that is then moved into the T

提交回复
热议问题