change const property through overloading

Joined
Feb 12, 2008
Messages
108
Reaction score
0
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
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top