I have a vector V which contains objects of type O. Generally, I want to prevent O from being copied so I've made the copy/assignment operators private.
On doing this, I've been getting compiler errors and I'm pretty sure that these relate to V which contains elements of typo O. I assume that V invokes O's copy constructor when using push_back and erase etc which explains the compiler errors.
Is there anyway to make O uncopyable but allow O to be used in V? I think move constructors might be helpful here but I'm not sure.
> Is that because std::ofstream has deleted copy constructor/assignment operator?
Yes.
> In general, you'd prevent A from being copied by deleting the copy constructor
> and assignment operator, right?
Yes. In that case, the rule of five would apply.
Because the presence of a user-defined destructor, copy-constructor, or copy-assignment operator prevents implicit definition of the move constructor and the move assignment operator, any class for which move semantics are desirable, has to declare all five special member functions https://en.cppreference.com/w/cpp/language/rule_of_three#Rule_of_five