Hidden get method for properties

Hasan Aljudy hasan.aljudy at gmail.com
Wed Jul 19 04:41:10 PDT 2006



sclytrack at 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.163

It'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;
> }
> 






More information about the Digitalmars-d-learn mailing list