Skip to content

Commit 2b4d523

Browse files
authored
Update initializing-classes-and-structs-without-constructors-cpp.md
Also fixing problematic uses of "default brace initialization", easily confused with "default initialization", which it doesn't do.
1 parent 645110d commit 2b4d523

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

docs/cpp/initializing-classes-and-structs-without-constructors-cpp.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ int main()
4242
// Member initialization (in order of declaration):
4343
TempData td{ 45978, time(&time_to_set), 28.9, 37.0, 16.7 };
4444

45-
// Value initialization = {0,0,0,0,0}
46-
TempData td_default{};
45+
// When there's no constructor, an empty brace initializer does
46+
// value initialization = {0,0,0,0,0}
47+
TempData td_emptyInit{};
4748

4849
// Uninitialized = if used, emits warning C4700 uninitialized local variable
4950
TempData td_noInit;
@@ -55,7 +56,7 @@ int main()
5556
}
5657
```
5758
58-
When a `class` or `struct` has no constructor, you provide the list elements in the order that the members are declared in the `class`. If the `class` has a constructor, provide the elements in the order of the parameters. If a type has a default constructor, either implicitly or explicitly declared, you can use default brace initialization (with empty braces). For example, the following `class` may be initialized by using both default and non-default brace initialization:
59+
When a `class` or `struct` has no constructor, you provide the list elements in the order that the members are declared in the `class`. If the `class` has a constructor, provide the elements in the order of the parameters. If a type has a default constructor, either implicitly or explicitly declared, you can use brace initialization with empty braces to invoke it. For example, the following `class` may be initialized by using both empty and non-empty brace initialization:
5960
6061
```cpp
6162
#include <string>
@@ -106,7 +107,7 @@ int main()
106107
}
107108
```
108109
109-
If the default constructor is explicitly declared but marked as deleted, default brace initialization can't be used:
110+
If the default constructor is explicitly declared but marked as deleted, empty brace initialization can't be used:
110111
111112
```cpp
112113
class class_f {

0 commit comments

Comments
 (0)