Skip to content

Commit 06ed8cd

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#3080 from MicrosoftDocs/master637535870261935141
Repo sync for protected CLA branch
2 parents 85f6475 + 95f7461 commit 06ed8cd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docs/cpp/abstract-classes-cpp.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ helpviewer_keywords: ["classes [C++], abstract", "base classes [C++], abstract c
88

99
Abstract classes act as expressions of general concepts from which more specific classes can be derived. You can't create an object of an abstract class type. However, you can use pointers and references to abstract class types.
1010

11-
You create an abstract class by declaring at least one pure virtual member function. That's a virtual function declared by using the pure specifier (`= 0`) syntax. Classes derived from the abstract class must implement the pure virtual function or they, too, are abstract classes.
11+
You create an abstract class by declaring at least one pure virtual member function. That's a virtual function declared by using the *pure* specifier (`= 0`) syntax. Classes derived from the abstract class must implement the pure virtual function or they, too, are abstract classes.
1212

1313
Consider the example presented in [Virtual functions](../cpp/virtual-functions.md). The intent of class `Account` is to provide general functionality, but objects of type `Account` are too general to be useful. That means `Account` is a good candidate for an abstract class:
1414

@@ -57,9 +57,14 @@ class base
5757
{
5858
public:
5959
base() {}
60-
virtual ~base() = 0 {}; // pure virtual, and defined!
60+
// To define the virtual destructor outside the class:
61+
virtual ~base() = 0;
62+
// Microsoft-specific extension to define it inline:
63+
// virtual ~base() = 0 {};
6164
};
6265
66+
base::~base() {} // required if not using Microsoft extension
67+
6368
class derived : public base
6469
{
6570
public:
@@ -73,7 +78,7 @@ int main()
7378
}
7479
```
7580

76-
The example shows the definition of `~base()` inline, but you can also define it outside the class by using `base::~base() {}`.
81+
The example shows how a Microsoft compiler extension lets you add an inline definition to pure virtual `~base()`. You can also define it outside the class by using `base::~base() {}`.
7782

7883
When the object `aDerived` goes out of scope, the destructor for class `derived` is called. The compiler generates code to implicitly call the destructor for class `base` after the `derived` destructor. The empty implementation for the pure virtual function `~base` ensures that at least some implementation exists for the function. Without it, the linker generates an unresolved external symbol error for the implicit call.
7984

0 commit comments

Comments
 (0)