Skip to content

Commit d523990

Browse files
authored
Merge pull request #5992 from TylerMSFT/c7742
new article
2 parents 2ab35ed + fc7b294 commit d523990

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ title: "Compiler Error C2462"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C2462"]
66
helpviewer_keywords: ["C2462"]
7-
ms.assetid: a8601bf8-f5ce-41de-9117-e2632bd4996b
87
---
98
# Compiler Error C2462
109

11-
'identifier' : cannot define a type in a 'new-expression'
10+
> 'identifier' : cannot define a type in a 'new-expression'
1211
1312
You cannot define a type in the operand field of the **`new`** operator. Put the type definition in a separate statement.
1413

1514
The following sample generates C2462:
1615

1716
```cpp
1817
// C2462.cpp
19-
int main() {
18+
int main()
19+
{
2020
new struct S { int i; }; // C2462
2121
}
2222
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
description: "Learn more about: Compiler Error C7742"
3+
title: "Compiler Error C7742"
4+
ms.date: "07/02/2025"
5+
ai-usage: ai-assisted
6+
f1_keywords: ["C7742"]
7+
helpviewer_keywords: ["C7742"]
8+
---
9+
# Compiler Error C7742
10+
11+
> *Identifier*: a forward declaration of an enum can only use a simple identifier
12+
13+
The C++ Standard doesn't allow declaring an opaque enumeration using a qualified-id. An opaque enum declaration specifies the name and the underlying type, but doesn't list the enumerators or their values.
14+
15+
The following example generates C7742:
16+
17+
```cpp
18+
// C7742.cpp
19+
class MyClass
20+
{
21+
public:
22+
enum MyEnum
23+
{
24+
e1,
25+
e2
26+
};
27+
};
28+
29+
enum MyClass::MyEnum; // C7742
30+
```
31+
32+
To fix this error, remove the opaque enumeration declaration because it doesn't add anything to the program.
33+
34+
However, you can define an enumeration with a qualified-id. For example:
35+
36+
```cpp
37+
struct S
38+
{
39+
enum E : int;
40+
};
41+
42+
enum S::E : int { e1, e2, e3 };
43+
```

docs/error-messages/compiler-errors-2/compiler-errors-c7500-through-c7999.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ The articles in this section of the documentation explain a subset of the error
240240
| Compiler error C7739 | cannot jump from this `goto` statement to its label |
241241
| Compiler error C7740 | cannot jump to case label |
242242
| Compiler error C7741 | ABI inconsistency: '*function*' was originally assumed to use '`C`' return semantics but now it requires '`C++`' return semantics |
243+
| [Compiler error C7742](compiler-error-c7742.md) | '*identifier*': a forward declaration of an enum can only use a simple identifier |
243244
| Compiler error C7800 | duplicate explicit instantiation definition of '*name*' |
244245
| Compiler error C7801 | '*function*': if one declaration of '*identifier*' has the '`[[msvc::disptach]]`' attribute then all functions must have the attribute |
245246
| Compiler error C7802 | '*identifier*': a capability must resolve to an enumerator |

docs/error-messages/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,6 +3169,8 @@ items:
31693169
href: compiler-warnings/c5208.md
31703170
- name: Compiler error C7688
31713171
href: compiler-errors-2/compiler-error-c7688.md
3172+
- name: Compiler error C7742
3173+
href: compiler-errors-2/compiler-error-c7742.md
31723174
- name: Compiler warnings C4000 through C5999
31733175
expanded: false
31743176
items:

0 commit comments

Comments
 (0)