diff options
| author | Yong He <yonghe@outlook.com> | 2025-06-13 22:13:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-13 22:13:00 -0700 |
| commit | 6a23949f07f4eba38086b656e7073ce3bf8cd2fe (patch) | |
| tree | 132bbe330b6027d323c74175686d006605e4da6d /docs/user-guide/06-interfaces-generics.md | |
| parent | e72b3325663ab6d4bb791742574b031f0df6328a (diff) | |
Allow interface methods to have default implementations. (#7439)
Diffstat (limited to 'docs/user-guide/06-interfaces-generics.md')
| -rw-r--r-- | docs/user-guide/06-interfaces-generics.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md index b90bc04ba..1912fcb02 100644 --- a/docs/user-guide/06-interfaces-generics.md +++ b/docs/user-guide/06-interfaces-generics.md @@ -43,8 +43,21 @@ struct MyType : IFoo, IBar uint myMethod2(uint2 x) {...} } ``` + In this case, the definition of `MyType` must satisfy the requirements from both the `IFoo` and `IBar` interfaces by providing both the `myMethod` and `myMethod2` methods. +Interface methods can have a default implementation, which will be used if a conforming type doesn't provide an overriding implementation. For example: + +```slang +interface IFoo +{ + int getVal() { return 0; } +} + +// OK, MyType.getVal() will use the default implementation provided in `IFoo`. +struct MyType : IFoo {} +``` + Generics --------------------- |
