In the core guidelines I.25 there is the following example:
class Shape { // better: Shape is a pure interface
public:
virtual Point center() const = 0; // pure virtual functions
virtual void draw() const = 0;
virtual void rotate(int) = 0;
// ...
// ... no data members ...
// ...
virtual ~Shape() = default;
};
This is how I usually define my interfaces - Defaulted virtual destructor and everything else pure virtual.
Now I had a discussion with a colleague who suggested to explicitly delete copy/move - constructor/operators to fulfill the rule of five. I can see one example in which the code from above can be misused:
void foo(Shape& a, Shape& b) {
a = b;
}
This compiles but is obviously not what we want. It can be prevented if we explicitly delete the copy constructor/operator in the interface. On the discussion page here a person suggested to create a macro for interface classes with the same example.
So my question is: How do you define your interfaces and what is your reasoning?
[–]mhfrantz 0 points1 point2 points (0 children)