August 20, 2007 Inheritance question | ||||
---|---|---|---|---|
| ||||
How do I hide A's getname()and use another method name for it? I wanted the user of my class B to use the getnewname() instead of using getname() which is inherited from class A.
class A {
private char[] _name;
public char[] getname() { return _name; }
...
}
class B : A {
public char[] getnewname() { return A.getname(); }
...
}
void main() {
B b;
...
writefln(b.getnewname());
}
--
negerns
|
August 20, 2007 Re: Inheritance question | ||||
---|---|---|---|---|
| ||||
Posted in reply to negerns | You could use deprecated like so: import std.stdio; class A { private char[] _name; this(char[] name) { _name = name; } public char[] getname() { return _name; } } class B : A { this(char[] name) { super(name); } public char[] getnewname() { return A.getname(); } deprecated char[] getname() { return A.getname(); } } void main() { B b = new B(cast(char[])"test"); writefln(b.getname()); //Error: function dep.B.getname is deprecated writefln(b.getnewname()); } |
Copyright © 1999-2021 by the D Language Foundation