diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/user-guide/02-conventional-features.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/user-guide/02-conventional-features.md b/docs/user-guide/02-conventional-features.md index be931d5cd..ace4ef6a8 100644 --- a/docs/user-guide/02-conventional-features.md +++ b/docs/user-guide/02-conventional-features.md @@ -145,6 +145,25 @@ struct MyData > #### Note #### > Slang allows for a trailing semicolon (`;`) on `struct` declarations, but does not require it. +Structure types can have constructors. Constructors are defined with the `__init` keyword: + +```hlsl +struct MyData +{ + int a; + __init() { a = 5; } + __init(int t) { a = t; } +} +void test() +{ + MyData d; // invokes default constructor, d.a = 5 + MyData h = MyData(4); // invokes overloaded constructor, h.a = 4 +} +``` + +> #### Note #### +> Slang currently does not allow default values on struct members, but we intend to support them in the future. + ### Enumeration Types Enumeration types can be introduced with the `enum` keyword to provide type-safe constants for a range of values: |
