Skip to content

Commit 043fbc0

Browse files
author
mikeblome
committed
deleted incorrect section
1 parent e96e61f commit 043fbc0

1 file changed

Lines changed: 1 addition & 42 deletions

File tree

docs/cpp/constructors-cpp.md

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Constructors (C++)"
3-
ms.date: "07/02/2019"
3+
ms.date: "09/05/2019"
44
helpviewer_keywords: ["constructors [C++]", "objects [C++], creating", "instance constructors"]
55
ms.assetid: 3e9f7211-313a-4a92-9584-337452e061a9
66
---
@@ -511,47 +511,6 @@ BaseClass3 ctor
511511
DerivedClass ctor
512512
```
513513

514-
## <a name="virtual_functions_in_constructors"></a> Virtual functions in constructors
515-
516-
We recommend that you be careful when you call virtual functions in constructors. Because the base class constructor is always invoked before the derived class constructor, the function that's called in the base constructor is the base class version, not the derived class version. In the following example, constructing a `DerivedClass` causes the `BaseClass` implementation of `print_it()` to execute before the `DerivedClass` constructor causes the `DerivedClass` implementation of `print_it()` to execute:
517-
518-
```cpp
519-
#include <iostream>
520-
using namespace std;
521-
522-
class BaseClass{
523-
public:
524-
BaseClass(){
525-
print_it();
526-
}
527-
virtual void print_it() {
528-
cout << "BaseClass print_it" << endl;
529-
}
530-
};
531-
532-
class DerivedClass : public BaseClass {
533-
public:
534-
DerivedClass() {
535-
print_it();
536-
}
537-
virtual void print_it(){
538-
cout << "Derived Class print_it" << endl;
539-
}
540-
};
541-
542-
int main() {
543-
544-
DerivedClass dc;
545-
}
546-
```
547-
548-
Here's the output:
549-
550-
```Output
551-
BaseClass print_it
552-
Derived Class print_it
553-
```
554-
555514
## <a name="delegating_constructors"></a> Delegating constructors
556515

557516
A *delegating constructor* calls a different constructor in the same class to do some of the work of initialization. This is useful when you have multiple constructors that all have to perform similar work. You can write the main logic in one constructor and invoke it from others. In the following trivial example, Box(int) delegates its work to Box(int,int,int):

0 commit comments

Comments
 (0)