Hi anon,
My bad example. I mean overriding, not overloading. I have tested we can change the parameter type from const to non-const (and vice versa) in base/derived class and it still works.
1. is it good code or good practice?
2. It yse in (1), are there any practical usage of this type of "overriding"?
Code:
class Base {
public:
const int foo () {return 200;}
const int goo (const int input) {return 200;}
};
class Derived : public Base {
public:
int foo() {return 100;}
int goo (int input) {return 200;}
};
int main()
{
Base b;
Derived d;
int rtn = b.foo();
rtn = d.foo();
return 0;
}
regards,
George
Originally Posted by
anon
Your concept code doesn't tell me much.
An integer called rtn is declared, and assigned 200 from b.foo(). Then it is assigned 100 from d.foo().
The return type of foo (int or const int) has no relevance in this code: the return value is assigned to a simple non-const int and you can do anything you like with it. The code would compile the same if you swapped the calls to d.foo() and b.foo().