Skip to content

Commit 6aa0ee2

Browse files
author
mikeblome
committed
fixed copy paste error and removed version name
1 parent 9bc36d4 commit 6aa0ee2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

docs/cpp/constructors-cpp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ If a constructor throws an exception, the order of destruction is the reverse of
471471
472472
## <a name="extended_aggregate"></a> Derived constructors and extended aggregate initialization
473473
474-
If the constructor of a base class is non-public, but accessible to a derived class, then under **/std:c++17** mode in Visual Studio 2017 version 15.7 and later you can't use empty braces to initialize an object of the derived type.
474+
If the constructor of a base class is non-public, but accessible to a derived class, then under **/std:c++17** mode in Visual Studio 2017 and later you can't use empty braces to initialize an object of the derived type.
475475
476476
The following example shows C++14 conformant behavior:
477477
@@ -493,7 +493,7 @@ Derived d2 {}; // OK in C++14: Calls Derived::Derived()
493493

494494
In C++17, `Derived` is now considered an aggregate type. It means that the initialization of `Base` via the private default constructor happens directly, as part of the extended aggregate initialization rule. Previously, the `Base` private constructor was called via the `Derived` constructor, and it succeeded because of the friend declaration.
495495

496-
The following example shows C++17 behavior in Visual Studio 2017 version 15.7 in **/std:c++17** mode:
496+
The following example shows C++17 behavior in Visual Studio 2017 and later in **/std:c++17** mode:
497497

498498
```cpp
499499
struct Derived;

docs/overview/cpp-conformance-improvements.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,41 @@ For more information, see [Constructors](../cpp/constructors-cpp.md#inheriting_c
12351235
12361236
[P0017R1](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0017r1.html)
12371237
1238+
If the constructor of a base class is non-public, but accessible to a derived class, then under **/std:c++17** mode in Visual Studio 2017 version 15.7 you can no longer use empty braces to initialize an object of the derived type.
1239+
The following example shows C++14 conformant behavior:
1240+
1241+
```cpp
1242+
struct Derived;
1243+
struct Base {
1244+
friend struct Derived;
1245+
private:
1246+
Base() {}
1247+
};
1248+
1249+
struct Derived : Base {};
1250+
Derived d1; // OK. No aggregate init involved.
1251+
Derived d2 {}; // OK in C++14: Calls Derived::Derived()
1252+
// which can call Base ctor.
1253+
```
1254+
1255+
In C++17, `Derived` is now considered an aggregate type. It means that the initialization of `Base` via the private default constructor happens directly, as part of the extended aggregate initialization rule. Previously, the `Base` private constructor was called via the `Derived` constructor, and it succeeded because of the friend declaration.
1256+
The following example shows C++17 behavior in Visual Studio version 15.7 in **/std:c++17** mode:
1257+
1258+
```cpp
1259+
struct Derived;
1260+
struct Base {
1261+
friend struct Derived;
1262+
private:
1263+
Base() {}
1264+
};
1265+
struct Derived : Base {
1266+
Derived() {} // add user-defined constructor
1267+
// to call with {} initialization
1268+
};
1269+
Derived d1; // OK. No aggregate init involved.
1270+
Derived d2 {}; // error C2248: 'Base::Base': cannot access
1271+
// private member declared in class 'Base'
1272+
```
12381273
12391274
### C++17: Declaring non-type template parameters with auto
12401275

0 commit comments

Comments
 (0)