I have an ID-Record class and I want to block callers / users from using the operator== since it is ambiguous (user may want to compare only data field for equality).
Here's my class:
#include <string>
#include <functional>
class ID_Record
{
public:
bool operator==(const ID_Record& other) const
{ throw std::bad_function_call(); }
unsigned int id; // Record ID used for database.
std::string value;
};
I would prefer to have operator==()
"blocked" at compile time, so the compiler can catch it rather than at runtime.
The compiler should generate an error for this code:
ID_Record a(6, "Tree");
ID_Record b(3, "Platinum");
if (a == b) std::cout "Records are equal\n"; // This line should fail compilation.
I want to block cases of compiler generated functionality also.