Code
class A
{
public:
void f(const int i);
};
void A::f(int i)
{
std::cout<<++i<<std::endl;
}
int main()
{
A a;
a.f(1);
}
Why compiler does not give an error in this case ? Why the definition overrides the constant argument ?
Also, when the argument is of type reference (&)
the compiler throws error but why not in this case ?
Is there any compiler flag to enable warning on these mentioned cases ?
I am interested more from compiler error POV. Because one can easily put declaration (const) and definition(non-constant) differently and still compiler accepts it. If a mistake can be made it will eventually be made. Why can't compiler complain when there is such difference present.