Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2008

Tip: Looking for answers? Try searching our database.

change const property through overloading

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
George3 - 23 Feb 2008 10:18 GMT
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
Ben Voigt [C++ MVP] - 03 Mar 2008 22:30 GMT
> Hello everyone,
>
[quoted text clipped - 6 lines]
> 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.

> Code:
> --------------------
[quoted text clipped - 29 lines]
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.