change const property through overloading

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
 
B

Ben Voigt [C++ MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top