If I remove the copy constructor, can't I get the implicit move constructor?
The following command will not compile (tested by both clang and gcc)
#include <vector>
struct Foo
{
Foo(int a=0) : m_a(a) {}
Foo(const Foo& f) = delete;
// Foo(Foo&& f) = default;
private:
int m_a;
};
int main()
{
std::vector<Foo> foovec;
foovec.emplace_back(44); // might resize, so might move
}
But if I don't remove the copy constructor, or if the move constructor is used by default,
this works. Thus, deleting the copy constructor disables the move constructor,
and why is this rational?
+3
source to share