You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/error-messages/compiler-errors-1/compiler-error-c2061.md
+22-13Lines changed: 22 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -14,44 +14,53 @@ The compiler found an identifier where it wasn't expected. Make sure that `ident
14
14
15
15
An initializer may be enclosed by parentheses. To avoid this problem, enclose the declarator in parentheses or make it a **`typedef`**.
16
16
17
-
This error could also be caused when the compiler detects an expression as a class template argument; use [typename](../../cpp/typename.md) to tell the compiler it is a type.
17
+
This error could also be caused when the compiler detects an expression as a class template argument; use [typename](../../cpp/typename.md) to tell the compiler it is a type, as shown in the following example:
18
18
19
19
The following sample generates C2061:
20
20
21
21
```cpp
22
22
// C2061.cpp
23
23
// compile with: /std:c++17
24
-
template <A a> // C2061
25
-
// Replace identifier `A` with `typename`:
26
-
// template <typename a>
24
+
25
+
template <A a> // C2061
27
26
classC1 {};
28
27
28
+
template <typenameAa> // ok
29
+
class C2 {};
30
+
29
31
template <typenameT>
30
-
class C2 {
32
+
class C3
33
+
{
31
34
// Both are valid since C++20
32
-
using Type1 = T::Type; // C2061
33
-
using Type2 = typename T::Type; // OK
35
+
using Type1 = T::Type; // C2061
36
+
using Type2 = typename T::Type; // OK
34
37
};
35
38
36
-
int main() {
39
+
intmain()
40
+
{
37
41
int x;
38
42
unsigned a1 = alignof(x); // C2061
39
-
unsigned a2 = alignof(int); // OK
40
-
unsigned a3 = alignof(decltype(x)); // OK
43
+
unsigned a2 = alignof(int); // OK
44
+
unsigned a3 = alignof(decltype(x)); // OK
41
45
}
42
46
```
43
47
48
+
To resolve the error with `template<A a> class C1{};`, use `template <typename a> class C1 {};`
49
+
To resolve the issue with `using Type1 = T::Type;`, use `using Type1 = typename T::Type;`
50
+
44
51
C2061 can occur if you pass an instance name to [typeid](../../extensions/typeid-cpp-component-extensions.md):
0 commit comments