Consider a base class wich prevent copy construction and copy assignement like this:
class NonCopyable {
public:
NonCopyable() = default;
~NonCopyable() = default;
NonCopyable(NonCopyable const&) = delete;
NonCopyable& operator=(NonCopyable const&) = delete;
};
Our developers can now include this class, and use it to disable copy for inherited classes, like this:
class CopyTest : public NonCopyable {
public:
CopyTest() {
std::cout << "copy test created" << std::endl;
}
~CopyTest() {
std::cout << "copy test deleted" << std::endl;
}
};
When I try to use the CopyTest
class:
CopyTest ct, ct1(ct);
or
CopyTest ct;
CopyTest ct1 = ct2;
The compiler emit an error : use of deleted function xxx
(where xxx is my deleted copy ctor, or copy operator)
Then, if I want to std::move
a CopyTest
object :
CopyTest ct;
CopyTest ct1 = std::move(ct);
The compiler emit the same error (use of deleted function xxx - where xxx remains my copy ctor or assignement operator).
If I remind correctly, it's because the developer has not defined the proper move ctor/assignement operator.
Is it possible to force the compiler to tell the developper of the CopyTest
class that the move error is here because he has not defined the proper move ctor/assignement operator, and not because the copy ctor/assignement operator is deleted on the base class?
Platform :
Debian 9
GCC 6.3.0
Compilation flags :
-fpermissive -ggdb -std=c++11
std::move
, after all). I wouldn't worry about it. – Cássio Renan