I\'m trying to call a function on a polymorphic item. But I get the following error message at compile time:
\'
this\' argument to member
You need to explicitly tell the compiler that your function will not modify any members:
bool const select(Tuple const & tup) const {
Indeed, you cannot call a non-const method a const object. But you also cannot call a non-const method through a pointer or reference to a const object (regardless of whether the referred-to object is const or not).
This means that this:
const SelectParam* ptr = whatever();
ptr->select(someTuple);
is ill-formed.
In your case, you've declared a pointer to a const SelectParam here on this line:
for (const SelectParam* p: selectionParams) {
Simply remove the const and it should work :-)
On the other hand, if select is never meant to modify the object, simply mark it as const:
virtual const bool select( Tuple const & t) const = 0;
And your code should also work.