Skip to content

Commit 6ac25ab

Browse files
authored
Merge pull request #5480 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to main to sync with https://github.com/MicrosoftDocs/cpp-docs (branch main)
2 parents c964a96 + 28cddbd commit 6ac25ab

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
---
22
description: "Learn more about: Compiler Error C2101"
33
title: "Compiler Error C2101"
4-
ms.date: "11/04/2016"
4+
ms.date: "03/04/2024"
55
f1_keywords: ["C2101"]
66
helpviewer_keywords: ["C2101"]
7-
ms.assetid: 42f0136f-8cc1-4f2b-be1c-721ec9278e66
87
---
98
# Compiler Error C2101
109

1110
'&' on constant
1211

13-
The address-of operator ( `&` ) must have an l-value as operand.
12+
The [address-of operator (**`&`**)](../../cpp/address-of-operator-amp.md) must have an l-value as operand.
1413

1514
The following sample generates C2101:
1615

1716
```cpp
1817
// C2101.cpp
19-
int main() {
20-
char test;
21-
test = &'a'; // C2101
22-
test = 'a'; // OK
18+
int main()
19+
{
20+
int* ptr = &123; // C2101
2321
}
2422
```
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
---
22
description: "Learn more about: Compiler Error C2102"
33
title: "Compiler Error C2102"
4-
ms.date: "11/04/2016"
4+
ms.date: "03/03/2024"
55
f1_keywords: ["C2102"]
66
helpviewer_keywords: ["C2102"]
7-
ms.assetid: d15b5fa3-fa46-4cd4-a3d2-3661646ecb7a
87
---
98
# Compiler Error C2102
109

1110
'&' requires l-value
1211

13-
The address-of operator ( `&` ) must have an l-value as operand.
12+
The [address-of operator (**`&`**)](../../cpp/address-of-operator-amp.md) must have an l-value as operand. Address of temporary values cannot be taken.
13+
14+
The following sample generates C2102:
15+
16+
```cpp
17+
// C2102.cpp
18+
int func()
19+
{
20+
return 1;
21+
}
22+
23+
int main()
24+
{
25+
int* ptr = &func(); // C2102
26+
}
27+
```
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
---
22
description: "Learn more about: Compiler Error C2103"
33
title: "Compiler Error C2103"
4-
ms.date: "11/04/2016"
4+
ms.date: "03/04/2024"
55
f1_keywords: ["C2103"]
66
helpviewer_keywords: ["C2103"]
7-
ms.assetid: dfe95972-35e9-469a-b8a8-52c849d4e4e4
87
---
98
# Compiler Error C2103
109

1110
'&' on register variable
1211

1312
You cannot take the address of a register.
13+
14+
The following sample generates C2103:
15+
16+
```c
17+
// C2103.c
18+
int main(void)
19+
{
20+
register int x = 1;
21+
int* ptr = &x; // C2103
22+
}
23+
```
24+
25+
> [!NOTE]
26+
> This error applies to C code.
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
---
22
description: "Learn more about: Compiler Error C2487"
33
title: "Compiler Error C2487"
4-
ms.date: "11/04/2016"
4+
ms.date: "03/04/2024"
55
f1_keywords: ["C2487"]
66
helpviewer_keywords: ["C2487"]
7-
ms.assetid: 95d734fb-64ac-488d-b799-64f084eecb09
87
---
98
# Compiler Error C2487
109

1110
'identifier' : member of dll interface class may not be declared with dll interface
1211

1312
You can declare a whole class, or certain members of a non-DLL interface class, with DLL interface. You cannot declare a class with DLL interface and then declare a member of that class with DLL interface.
13+
14+
The following sample generates C2487:
15+
16+
```cpp
17+
// C2487.cpp
18+
// compile with: /c
19+
class __declspec(dllexport) C
20+
{
21+
__declspec(dllexport) void func() {} // C2487
22+
};
23+
```
24+
25+
To resolve this error, remove the DLL interface on the class or the members.
26+
27+
## See also
28+
29+
[Using `dllimport` and `dllexport` in C++ classes](../../cpp/using-dllimport-and-dllexport-in-cpp-classes.md)

0 commit comments

Comments
 (0)