This is a followup to Does a class with all attributes const need to have member function declared const as well?.
So I've a class PermutationGroup
whose all attribute are const. The compiler still make the distinction between const and non-const instance:
struct Foo {
const int bar;
void meth();
};
int main() {
Foo foo {2};
foo.meth(); // correct
const Foo cfoo {1};
cfoo.meth(); // wrong
};
As noticed by @nosid in the referred question One cannot call a non const
member function a const instance:
bla.cpp: In function ‘int main()’:
bla.cpp:10:14: error: passing ‘const Foo’ as ‘this’ argument of ‘void Foo::meth()’ discards qualifiers [-fpermissive]
cfoo.meth();
So the question is: why is it possible to declare non const instance of a class whose attribute are all const. Is there any reasonable use of that ?