digitalmars.D.learn - Inheritance question
- negerns (19/19) Aug 20 2007 How do I hide A's getname()and use another method name for it? I wanted
 - Regan Heath (17/17) Aug 20 2007 You could use deprecated like so:
 
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
 Aug 20 2007
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());
}
 Aug 20 2007








 
 
 
 Regan Heath <regan netmail.co.nz>