c++constructorabstract-class

Should a C++ interface (abstract class with just pure virtual functions) delete the copy/move assignment constructors


I have a a lot of public interfaces (actually abstract classes with just pure-virtual functions). Only the destructor is marked as default but wouldn't it be more cleaner to delete the copy/move constructors and copy/move assignment operators? Is there actually a guideline for such "interfaces" that one should delete these constructors/assignment operators? Like:

class MyInterface
{
  public:
    virtual ~MyInterface() = default; 
    MyInterface(const MyInterface&) = delete;
    MyInterface(const MyInterface&&) = delete;
    MyInterface& operator=(const MyInterface&) = delete;
    MyInterface& operator=(const MyInterface&&) = delete;
 
    [[nodiscard]] virtual std::string getName() const = 0;
    ...
};

Solution

  • Copying is about data. Since here there are no data members trying to do anything about copy/move semantics makes no sense.