digitalmars.D.learn - Calling Base Class Overriden Methods
- Jeroen Bollen (11/11) Nov 18 2013 How do I call a parent class's overidden method?
- Adam D. Ruppe (19/20) Nov 18 2013 super.method
- Jeroen Bollen (3/24) Nov 18 2013 Thanks! :D
- Adam D. Ruppe (2/3) Nov 18 2013 blargh, i thought it was, but can't find it either....
- H. S. Teoh (8/9) Nov 18 2013 Submit a bug to the bugtracker with "[dox]" in its subject line. This is
- Kenji Hara (15/26) Nov 18 2013 http://dlang.org/function#virtual-functions
How do I call a parent class's overidden method? module test; abstract class SuperClass { public pure void methodA() { } } class SubClass { public override pure void methodB() { // How do I call the parent methodA() from here? } }
Nov 18 2013
On Monday, 18 November 2013 at 19:32:39 UTC, Jeroen Bollen wrote:How do I call a parent class's overidden method?super.method so abstract class SuperClass { public pure void methodA() { } } class SubClass : SuperClass { public override pure void methodA() { // calls the parents super.methodA(); } } To do it from outside the class, you write the class name: void main() { auto obj = new SubClass(); obj.SuperClass.methodA(); // calls the specific super method }
Nov 18 2013
On Monday, 18 November 2013 at 19:34:56 UTC, Adam D. Ruppe wrote:On Monday, 18 November 2013 at 19:32:39 UTC, Jeroen Bollen wrote:Thanks! :D Why aren't these things in the documentation? :/How do I call a parent class's overidden method?super.method so abstract class SuperClass { public pure void methodA() { } } class SubClass : SuperClass { public override pure void methodA() { // calls the parents super.methodA(); } } To do it from outside the class, you write the class name: void main() { auto obj = new SubClass(); obj.SuperClass.methodA(); // calls the specific super method }
Nov 18 2013
On Monday, 18 November 2013 at 19:36:07 UTC, Jeroen Bollen wrote:Why aren't these things in the documentation? :/blargh, i thought it was, but can't find it either....
Nov 18 2013
On Mon, Nov 18, 2013 at 08:36:06PM +0100, Jeroen Bollen wrote: [...]Why aren't these things in the documentation? :/Submit a bug to the bugtracker with "[dox]" in its subject line. This is the only way to guarantee the docs will improve. T -- Answer: Because it breaks the logical sequence of discussion. Question: Why is top posting bad?
Nov 18 2013
On Monday, 18 November 2013 at 19:36:07 UTC, Jeroen Bollen wrote:On Monday, 18 November 2013 at 19:34:56 UTC, Adam D. Ruppe wrote:http://dlang.org/function#virtual-functions ========================= To avoid dynamic binding on member function call, insert base class name before the member function name. For example: ... void main() { auto d = new D(); assert(d.foo() == 3); // calls D.foo assert(d.B.foo() == 1); // calls B.foo assert(d.C.foo() == 2); // calls C.foo d.test(); } ========================= Kenji HaraTo do it from outside the class, you write the class name: void main() { auto obj = new SubClass(); obj.SuperClass.methodA(); // calls the specific super method }Thanks! :D Why aren't these things in the documentation? :/
Nov 18 2013