Adding overloaded methods
Ali Çehreli
acehreli at yahoo.com
Tue Feb 21 19:19:46 PST 2012
On 02/21/2012 06:21 PM, BLM wrote:
> I'm working on a project where I'm using overloaded virtual methods, and I've
> run into a challenge with overload sets.
>
> My code looks something like this:
>
> class Base {
> void get(ubyte b) {};
> }
>
> class Derived: Base {
> //alias Base.get get;
> void get(string s) {};
> }
>
> I've tried using an alias declaration to combine the two classes' overload
> sets in the derived class, but DMD complains that the alias conflicts with
> get(string). Is there some reasonably elegant way around this, or is it a
> limitation of the language?
Your code actually works with dmd 2.058:
import std.stdio;
class Base {
void get(ubyte b) {
writeln("get(ubyte)");
}
}
class Derived: Base {
alias Base.get get;
void get(string s) {
writeln("get(string)");
}
}
void main()
{
ubyte b;
string s;
auto o = new Derived();
o.get(b);
o.get(s);
}
Outputs:
get(ubyte)
get(string)
I have also corrected the indentation ;) and two extraneous semicolons.
Ali
More information about the Digitalmars-d-learn
mailing list