Skip to content

Structure error references in range [C2881, C2910] #5645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2881.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2881"
title: "Compiler Error C2881"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2881"
ms.date: 11/04/2016
f1_keywords: ["C2881"]
helpviewer_keywords: ["C2881"]
ms.assetid: b49c63c2-b064-4d4b-a75e-ddd2af947522
---
# Compiler Error C2881

'namespace1' : is already used as an alias for 'namespace2'
> 'namespace1' : is already used as an alias for 'namespace2'

## Remarks

You cannot use the same name as an alias for two namespaces.

The following sample generates C2881:
## Example

The following example generates C2881:

```cpp
// C2881.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2882.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2882"
title: "Compiler Error C2882"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2882"
ms.date: 11/04/2016
f1_keywords: ["C2882"]
helpviewer_keywords: ["C2882"]
ms.assetid: 617018ee-5a0d-4b8d-9612-77e8ae52679b
---
# Compiler Error C2882

'name' : illegal use of namespace identifier in expression
> 'name' : illegal use of namespace identifier in expression

## Remarks

You tried to use the name of a namespace in an expression.

The following sample generates C2882:
## Example

The following example generates C2882:

```cpp
// C2882.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2883.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2883"
title: "Compiler Error C2883"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2883"
ms.date: 11/04/2016
f1_keywords: ["C2883"]
helpviewer_keywords: ["C2883"]
ms.assetid: 5c6d689d-ed42-41ad-b5c0-e9c2e0b8c356
---
# Compiler Error C2883

'name' : function declaration conflicts with 'identifier' introduced by using-declaration
> 'name' : function declaration conflicts with 'identifier' introduced by using-declaration

## Remarks

You tried to define a function more than once. The first definition was made from a namespace with a **`using`** declaration. The second was a local definition.

The following sample generates C2883:
## Example

The following example generates C2883:

```cpp
// C2883.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2884.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2884"
title: "Compiler Error C2884"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2884"
ms.date: 11/04/2016
f1_keywords: ["C2884"]
helpviewer_keywords: ["C2884"]
ms.assetid: 8b4d43e3-3fb5-4360-86c8-de59d8736d4f
---
# Compiler Error C2884

'name' : introduced by using-declaration conflicts with local function 'function'
> 'name' : introduced by using-declaration conflicts with local function 'function'

## Remarks

You tried to define a function more than once. The first definition is a local definition. The second is from a namespace with a **`using`** declaration.

The following sample generates C2884:
## Example

The following example generates C2884:

```cpp
// C2884.cpp
Expand Down
13 changes: 7 additions & 6 deletions docs/error-messages/compiler-errors-2/compiler-error-c2885.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
description: "Learn more about: Compiler Error C2885"
title: "Compiler Error C2885"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2885"
ms.date: 11/04/2016
f1_keywords: ["C2885"]
helpviewer_keywords: ["C2885"]
ms.assetid: 7743e5f3-a034-44b4-9ee8-5a6254c27f8c
---
# Compiler Error C2885

'class::identifier' : not a valid using-declaration at non-class scope
> 'class::identifier' : not a valid using-declaration at non-class scope

## Remarks

You used a [using](../../cpp/using-declaration.md) declaration incorrectly.

This error can be generated as a result of compiler conformance work that was done for Visual Studio 2005: it is no longer valid to have a **`using`** declaration to a nested type; you must explicitly qualify each reference you make to the nested type, put the type in a namespace, or create a typedef.

## Examples

The following sample generates C2885.
The following example generates C2885.

```cpp
// C2885.cpp
Expand Down Expand Up @@ -47,7 +48,7 @@ int main () {

If you use the **`using`** keyword with a class member, C++ requires you to define that member inside another class (a derived class).

The following sample generates C2885.
The following example generates C2885.

```cpp
// C2885_b.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2886.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2886"
title: "Compiler Error C2886"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2886"
ms.date: 11/04/2016
f1_keywords: ["C2886"]
helpviewer_keywords: ["C2886"]
ms.assetid: c01588a1-484c-4dc9-a3f1-f900c6e44543
---
# Compiler Error C2886

'class::identifier' : symbol cannot be used in a member using-declaration
> 'class::identifier' : symbol cannot be used in a member using-declaration

## Remarks

A **`using`** declaration uses a symbol, such as a namespace name. A **`using`** declaration is for declaring base class members.

The following sample generates C2886:
## Example

The following example generates C2886:

```cpp
// C2886.cpp
Expand Down
8 changes: 6 additions & 2 deletions docs/error-messages/compiler-errors-2/compiler-error-c2888.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ helpviewer_keywords: ["C2888"]
---
# Compiler Error C2888

'identifier' : symbol cannot be defined within namespace 'namespace'
> 'identifier' : symbol cannot be defined within namespace 'namespace'

## Remarks

A symbol belonging to namespace A must be defined in a namespace that encloses A.

The following sample generates C2888:
## Example

The following example generates C2888:

```cpp
// C2888.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2890.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2890"
title: "Compiler Error C2890"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2890"
ms.date: 11/04/2016
f1_keywords: ["C2890"]
helpviewer_keywords: ["C2890"]
ms.assetid: 49147375-182c-42b1-b170-f475cd436d47
---
# Compiler Error C2890

'class' : a ref class can only have one non-interface base class
> 'class' : a ref class can only have one non-interface base class

## Remarks

A reference class can only have one base class.

The following sample generates C2890:
## Example

The following example generates C2890:

```cpp
// C2890.cpp
Expand Down
10 changes: 8 additions & 2 deletions docs/error-messages/compiler-errors-2/compiler-error-c2891.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ helpviewer_keywords: ["C2891"]
---
# Compiler Error C2891

'parameter' : cannot take the address of a template parameter
> 'parameter' : cannot take the address of a template parameter

You can't take the address of a template parameter unless it is an lvalue. Type parameters are not lvalues because they have no address. Non-type values in template parameter lists that are not lvalues also do not have an address. This is an example of code that causes Compiler Error C2891, because the value passed as the template parameter is a compiler-generated copy of the template argument.
## Remarks

You can't take the address of a template parameter unless it is an lvalue. Type parameters are not lvalues because they have no address. Non-type values in template parameter lists that are not lvalues also do not have an address.

## Example

This is an example of code that causes Compiler Error C2891, because the value passed as the template parameter is a compiler-generated copy of the template argument.

```cpp
template <int i> int* f() { return &i; }
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-2/compiler-error-c2892.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2892"
title: "Compiler Error C2892"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2892"
ms.date: 11/04/2016
f1_keywords: ["C2892"]
helpviewer_keywords: ["C2892"]
ms.assetid: c22a5084-2f50-42c2-a56b-6dfe5442edc9
---
# Compiler Error C2892

local class shall not have member templates
> local class shall not have member templates

## Remarks

Templated member functions are not valid in a class that is defined in a function.

The following sample generates C2892:
## Example

The following example generates C2892:

```cpp
// C2892.cpp
Expand Down
8 changes: 5 additions & 3 deletions docs/error-messages/compiler-errors-2/compiler-error-c2893.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
---
title: "Compiler Error C2893"
description: "Learn more about: Compiler Error C2893"
ms.date: "11/04/2016"
ms.date: 11/04/2016
f1_keywords: ["C2893"]
helpviewer_keywords: ["C2893"]
---
# Compiler Error C2893

Failed to specialize function template 'template name'
> Failed to specialize function template 'template name'

## Remarks

The compiler failed to specialize a function template. There can be many causes for this error.

In general, the way to resolve a C2893 error is to review the function's signature and make sure you can instantiate every type.

## Example

C2893 occurs because `f`'s template parameter `T` is deduced to be `std::map<int,int>`, but `std::map<int,int>` has no member `data_type` (`T::data_type` can not be instantiated with `T = std::map<int,int>`.). The following sample generates C2893.
C2893 occurs because `f`'s template parameter `T` is deduced to be `std::map<int,int>`, but `std::map<int,int>` has no member `data_type` (`T::data_type` can not be instantiated with `T = std::map<int,int>`.). The following example generates C2893.

```cpp
// C2893.cpp
Expand Down
15 changes: 9 additions & 6 deletions docs/error-messages/compiler-errors-2/compiler-error-c2894.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2894"
title: "Compiler Error C2894"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2894"
ms.date: 11/04/2016
f1_keywords: ["C2894"]
helpviewer_keywords: ["C2894"]
ms.assetid: 4e250579-2b59-4993-a6f4-49273e7ecf06
---
# Compiler Error C2894

templates cannot be declared to have 'C' linkage
> templates cannot be declared to have 'C' linkage

## Remarks

This error can be caused by a template defined inside an `extern "C"` block.

The following sample generates C2894:
## Examples

The following example generates C2894:

```cpp
// C2894.cpp
Expand All @@ -23,7 +26,7 @@ extern "C" {
}
```

The following sample generates C2894:
The following example generates C2894:

```cpp
// C2894b.cpp
Expand Down
9 changes: 6 additions & 3 deletions docs/error-messages/compiler-errors-2/compiler-error-c2896.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
---
description: "Learn more about: Compiler Error C2896"
title: "Compiler Error C2896"
description: "Learn more about: Compiler Error C2896"
ms.date: 06/01/2022
f1_keywords: ["C2896"]
helpviewer_keywords: ["C2896"]
ms.assetid: b600407b-cb05-42e3-9069-2aa6960f0eaa
---
# Compiler Error C2896

> '*function1*' : cannot use function template '*function2*' as argument

## Remarks

A function template can't be an argument to another function template.

This error is obsolete in Visual Studio 2022 and later versions.

The following sample generates C2896:
## Examples

The following example generates C2896:

```cpp
// C2896.cpp
Expand Down
13 changes: 7 additions & 6 deletions docs/error-messages/compiler-errors-2/compiler-error-c2897.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
---
description: "Learn more about: Compiler Error C2897"
title: "Compiler Error C2897"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2897"
ms.date: 11/04/2016
f1_keywords: ["C2897"]
helpviewer_keywords: ["C2897"]
ms.assetid: a88349e2-823f-42a0-8660-0653b677afa4
---
# Compiler Error C2897

a destructor/finalizer cannot be a function template
> a destructor/finalizer cannot be a function template

## Remarks

Destructors or finalizers cannot be overloaded, so declaring a destructor as a template (which would define a set of destructors) is not allowed.

## Examples

The following sample generates C2897.
The following example generates C2897.

```cpp
// C2897.cpp
Expand All @@ -25,7 +26,7 @@ public:
};
```

The following sample generates C2897.
The following example generates C2897.

```cpp
// C2897_b.cpp
Expand Down
Loading