Skip to content

Commit

Permalink
Add documentation for issue 8809
Browse files Browse the repository at this point in the history
This language feature has not been clearly documented.
  • Loading branch information
9rnsr committed Oct 14, 2012
1 parent deb29c6 commit 946692f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions function.dd
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,36 @@ class Bar : Foo {
the function is called.
)

$(P To avoid dynamic binding on member function call, insert
base class name before the member function name. For example:
)

------
class B {
int foo() { return 1; }
}
class C : B {
override int foo() { return 2; }

void test() {
assert(B.foo() == 1); // translated to this.A.foo(), and

This comment has been minimized.

Copy link
@repeatedly

repeatedly Oct 14, 2012

Member

Where is 'A'?

This comment has been minimized.

Copy link
@9rnsr

9rnsr Oct 14, 2012

Author Contributor

It's a typo. Will fix.

// calls B.foo statically.
assert(C.foo() == 2); // calls C.foo statically, even if
// the actual instance of 'this' is D.
}
}
class D : C {
override int foo() { return 3; }
}
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();
}
------

<h3>$(LNAME2 function-inheritance, Function Inheritance and Overriding)</h3>

A functions in a derived class with the same name and parameter
Expand Down

1 comment on commit 946692f

@9rnsr
Copy link
Contributor Author

@9rnsr 9rnsr commented on 946692f Oct 14, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I had try to make pull request through web interface, but accidentally commit the change into master.
But, I believe this is correct documentation...

Please sign in to comment.