digitalmars.D.learn - Hidden get method for properties
- sclytrack pi.be (40/40) Jul 19 2006 I've only been using D sinds June 2006, I stumbled accross this today.
- Hasan Aljudy (5/61) Jul 19 2006 It's got to do with function overloading in the derived class.
- Lars Ivar Igesund (9/27) Jul 19 2006 It has to do with the overload rules in D, which are taken from C++. It
- sclytrack pi.be (4/31) Jul 19 2006 Yeah, I found it a bit confusing. I'm sure Walter has a reason for desig...
-
Stewart Gordon
(8/24)
Jul 19 2006
I've only been using D sinds June 2006, I stumbled accross this today. Is this normal D behavior that int number() is no longer accessible from the derived class while backupNumber still is? I can work around this, without problems. :-) dmd v0.163 import std.stdio; class BaseClass { protected: int _number; public: int number() { return _number; } int backupNumber() { return _number; } } class BaseDerived:BaseClass { public: void number(int value) { _number = value + 1; } } int main() { BaseDerived derived = new BaseDerived(); derived.number = 10; writefln( derived.number ); //Error //main.d(35): function main.BaseDerived.number (int) does not match argument types () //main.d(35): Error: expected 1 arguments, not 0 //main.d(35): voids have no value return 0; } One day, I will have a real girlfriend.
Jul 19 2006
sclytrack pi.be wrote:I've only been using D sinds June 2006, I stumbled accross this today. Is this normal D behavior that int number() is no longer accessible from the derived class while backupNumber still is? I can work around this, without problems. :-) dmd v0.163It's got to do with function overloading in the derived class. When you overload number in Derived, you lose visibility to the other number method(s). As for why is that? I don't know. Maybe to prevent possible confusion.import std.stdio; class BaseClass { protected: int _number; public: int number() { return _number; } int backupNumber() { return _number; } } class BaseDerived:BaseClass { public: void number(int value) { _number = value + 1; } } int main() { BaseDerived derived = new BaseDerived(); derived.number = 10; writefln( derived.number ); //Error //main.d(35): function main.BaseDerived.number (int) does not match argument types () //main.d(35): Error: expected 1 arguments, not 0 //main.d(35): voids have no value return 0; }
Jul 19 2006
Hasan Aljudy wrote:sclytrack pi.be wrote:It has to do with the overload rules in D, which are taken from C++. It turns out that the issues people find with this feature in D, isn't particularly present when using C++, so people are quite often confused with the current operation (which is quite opposite to how it works in Java). The solution in this case is to use alias to pull the symbol into the namespace of the subclass: alias BaseClass.number number;I've only been using D sinds June 2006, I stumbled accross this today. Is this normal D behavior that int number() is no longer accessible from the derived class while backupNumber still is? I can work around this, without problems. :-) dmd v0.163It's got to do with function overloading in the derived class. When you overload number in Derived, you lose visibility to the other number method(s). As for why is that? I don't know. Maybe to prevent possible confusion.
Jul 19 2006
In article <e9l7d5$1g4j$1 digitaldaemon.com>, Lars Ivar Igesund says...Hasan Aljudy wrote:Yeah, I found it a bit confusing. I'm sure Walter has a reason for designing it this way, but is too busy to answer this. Thanks for your reply, Sclytrack.sclytrack pi.be wrote:It has to do with the overload rules in D, which are taken from C++. It turns out that the issues people find with this feature in D, isn't particularly present when using C++, so people are quite often confused with the current operation (which is quite opposite to how it works in Java). The solution in this case is to use alias to pull the symbol into the namespace of the subclass: alias BaseClass.number number;I've only been using D sinds June 2006, I stumbled accross this today. Is this normal D behavior that int number() is no longer accessible from the derived class while backupNumber still is? I can work around this, without problems. :-) dmd v0.163It's got to do with function overloading in the derived class. When you overload number in Derived, you lose visibility to the other number method(s). As for why is that? I don't know. Maybe to prevent possible confusion.
Jul 19 2006
Hasan Aljudy wrote:sclytrack pi.be wrote:<snip> It carries over from C++ days. AIUI the point is to avert a scenario whereby a base class can gain a new overload of the method name, and thereby cause a call to use this instead of your function in the derived class. See http://tinyurl.com/owwve Stewart.I've only been using D sinds June 2006, I stumbled accross this today. Is this normal D behavior that int number() is no longer accessible from the derived class while backupNumber still is? I can work around this, without problems. :-) dmd v0.163It's got to do with function overloading in the derived class. When you overload number in Derived, you lose visibility to the other number method(s). As for why is that? I don't know. Maybe to prevent possible confusion.
Jul 19 2006