change const property through overloading

  • Thread starter Thread starter George3
  • Start date Start date
G

George3

Hello everyone,


I have tried compiler allows to change const property of an overloaded
method. Here is my proof of concept code.

My question,

1. is it good code or good practice?
2. It yse in (1), are there any practical usage of this type of
"overloading"?


Code:
--------------------

class Base {
public:
const int foo() {return 200;};
};

class Derived : public Base {
public:
int foo() {return 100;};
};

int main()
{
Base b;
Derived d;
int rtn = b.foo();
rtn = d.foo();

return 0;
}

--------------------



thanks in advance,
George
 
George3 said:
Hello everyone,


I have tried compiler allows to change const property of an overloaded
method. Here is my proof of concept code.

My question,

1. is it good code or good practice?
2. It yse in (1), are there any practical usage of this type of
"overloading"?

First, you are not overloading, you cannot overload by return type, and you
cannot overload names in a base class.
You are also not overriding, because the base definition is not virtual.
You are simply hiding the base name.

Furthermore, the top level const of a return type is meaningless.
 
Back
Top