I would like to define an abstract base class X and do the following:
a) each concrete class Y inheriting from X defines a constructor Y (int x)
b) it should be possible to check if two objects of Y are equal.
For a, one not-so-good solution is to put a pure virtual fromInt method in X which the concrete class will have to define. But I can’t enforce.
For b) I cannot use pure virtual method in X
bool operator == (const X& other) const =0;
since in overridden classes this remains undefined. Not enough to determine
bool operator == (const Y& other) const { //stuff}
because the types do not match. How to solve these problems?
source
share