是否有可能在C++ 11中使用没有可复制对象(有引用实例)的std :: vector?
struct CanNotCopy {
int& intref_;
CanNotCopy(int& i) noexcept : intref_(i) {}
// How do I make move constructor and operator = ?
};
std::vector<CanNotCopy> hoge; // OK
hoge.resize(10); // default constructor required
int j = 123;
hoge[1] = CanNotCopy(j); // copy constructor required
Run Code Online (Sandbox Code Playgroud)