Code
class A { public: void f(const int i); }; void A::f(int i) { std::cout<<++i<<std::endl; } int main() { A a; af(1); }
Why does the compiler not give an error in this case? Why does a definition override a constant argument? In addition, when the argument is of type reference (&) , the compiler throws an error, but why not in this case?
Is there any compiler flag to enable a warning about these mentioned cases?
I'm more interested in the POV compiler error. Because you can easily put a declaration (const) and a definition (mutable) in different ways, and still the compiler accepts it. If a mistake can be made, it will eventually be made. Why can't the compiler complain when there is such a difference.
source share