I wrote code when one class has only constant access to its content, and that was inherited by other class which provides the same method, but with normal access to its members. When I try to compile it by gcc I get following error code:
error: passing ‘const A’ as ‘this’ argument of ‘void A::operator()()’ discards qualifiers
here is sample compilable code:
#include<stdio.h>
class ConstA {
public:
void operator()() const {
printf("const\n");
}
};
class A : public ConstA {
public:
void operator()() {
printf("non-const\n");
}
};
class B : public A {
};
void f(const A& a) {
a();
}
int main() {
B b;
f(b);
}
Compiler tries to invoke method(operator ()) without const attribute, while const method is accessible in base ConstA class. I do not know why I get this kind of error.