Might have been copied from a template.
template<class T>
class hashBase {
virtual int hash( const T& c ) = 0;
// other stuff: save hash, compare, etc.
};
class intHash : hashBase<int> {
int hash( const int& c ) override { /* c=1; ERROR */ return 1; }
};
struct structData{ int a; };
class structHash : hashBase<structData> {
int hash( const structData& c ) override { /* c.a=1; ERROR */ return 1; }
};
class structPtrHash : hashBase<structData*> {
int hash( structData* const& c ) override { c->a=1; return 1; }
};
I wanted to make a generic class to calculate hashes.
intHash: set the parameter as constant
structHash: changed the signature to reference
structPtrHash: the only way it would compile
I reached this questing looking for "reference to a pointer of a constant",
which was not achieved in my code.
The top comments of this question:
What is the difference between const int*, const int * const, and int const *?
recommends:
Clockwise/Spiral Rule
cdecl.org
The correct pattern for my case:
class constStructPtrHash : hashBase<const structData*> {
int hash( const structData* const& c ) override { /* c->a=1; ERROR */ return 1; }
};