Skip to content

Commit 57e7d36

Browse files
authored
Merge pull request MicrosoftDocs#3649 from corob-msft/docs/corob/cpp-docs-3239
Address cpp-docs-3239
2 parents b50a678 + 59d8998 commit 57e7d36

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

docs/error-messages/compiler-errors-1/compiler-error-c2259.md

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
description: "Learn more about: Compiler Error C2259"
33
title: "Compiler Error C2259"
4-
ms.date: "11/04/2016"
4+
ms.date: 07/08/2021
55
f1_keywords: ["C2259"]
66
helpviewer_keywords: ["C2259"]
77
ms.assetid: e458236f-bdea-4786-9aa6-a98d8bffa5f4
88
---
99
# Compiler Error C2259
1010

11-
'class' : cannot instantiate abstract class
11+
> '*class*' : cannot instantiate abstract class
1212
1313
Code declares an instance of an abstract class or structure.
1414

15-
You cannot instantiate a class or structure with one or more pure virtual functions. To instantiate objects of a derived class, the derived class must override each pure virtual function.
15+
You can't instantiate a class or structure with one or more pure virtual functions. To instantiate objects of a derived class, the derived class must override each pure virtual function.
1616

1717
For more information, see [Implicitly abstract classes](../../dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli.md#BKMK_Implicitly_abstract_classes).
1818

@@ -35,15 +35,11 @@ A a; // C2259, A inherits func() as pure virtual
3535
B b; // OK, B defines func()
3636
```
3737
38-
Whenever you derive from an interface and implement the interface methods in the derived class with access permissions other than public, you may receive C2259. This occurs because the compiler expects the interface methods implemented in the derived class to have public access. When you implement the member functions for an interface with more restrictive access permissions, the compiler does not consider them to be implementations for the interface methods defined in the interface, which in turn makes the derived class an abstract class.
38+
Whenever you derive from an interface and implement the interface methods in the derived class with access permissions other than `public`, you may receive C2259. The error occurs because the compiler expects the interface methods implemented in the derived class to have `public` access.
3939
40-
There are two possible workarounds for the problem:
40+
To resolve this issue, don't use more restrictive access permissions for the implementation methods. The compiler doesn't consider them as implementations for the interface methods defined in the interface. In turn, that makes the derived class an abstract class. Instead, make the access permissions `public` for the implemented methods.
4141
42-
- Make the access permissions public for the implemented methods.
43-
44-
- Use the scope resolution operator for the interface methods implemented in the derived class to qualify the implemented method name with the name of the interface.
45-
46-
C2259 can also occur as a result of conformance work that was done in Visual Studio 2005, **/Zc:wchar_t** is now on by default. In this situation, C2599 can be resolved either by compiling with **/Zc:wchar_t-**, to get the behavior from previous versions, or preferably, by updating your types so they are compatible. For more information, see [/Zc:wchar_t (wchar_t Is Native Type)](../../build/reference/zc-wchar-t-wchar-t-is-native-type.md).
42+
C2259 can also occur because of conformance work that was done in Visual Studio 2005, **`/Zc:wchar_t`** is now on by default. In this situation, C2599 can be resolved either by compiling with **`/Zc:wchar_t-`**, to get the behavior from previous versions, or preferably, by updating your types so they're compatible. For more information, see [`/Zc:wchar_t` (wchar_t Is Native Type)](../../build/reference/zc-wchar-t-wchar-t-is-native-type.md).
4743
4844
The following sample generates C2259:
4945
@@ -96,9 +92,7 @@ ref class MyDerivedClass: public MyInterface {
9692
private:
9793
// Uncomment the following line to resolve.
9894
// public:
99-
void MyMethod(){}
100-
// or the following line
101-
// void MyInterface::MyMethod() {};
95+
virtual void MyMethod(){}
10296
};
10397

10498
int main() {

0 commit comments

Comments
 (0)