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
+33-9Lines changed: 33 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -14,30 +14,54 @@ 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
-
// compile with: /c
24
-
template < A a > // C2061
25
-
// try the following line instead
26
-
// template < typename b >
27
-
classc{};
23
+
// compile with: /std:c++17
24
+
25
+
template <A a> // C2061
26
+
classC1 {};
27
+
28
+
template <typenameAa> // ok
29
+
class C2 {};
30
+
31
+
template <typenameT>
32
+
class C3
33
+
{
34
+
// Both are valid since C++20
35
+
using Type1 = T::Type; // C2061
36
+
using Type2 = typename T::Type; // OK
37
+
};
38
+
39
+
intmain()
40
+
{
41
+
int x;
42
+
unsigned a1 = alignof(x); // C2061
43
+
unsigned a2 = alignof(int); // OK
44
+
unsigned a3 = alignof(decltype(x)); // OK
45
+
}
28
46
```
29
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
+
To resolve the issue with `alignof(x)`, replace the argument with the type of `x`. In this case, `int` or `decltype(x);`
51
+
30
52
C2061 can occur if you pass an instance name to [typeid](../../extensions/typeid-cpp-component-extensions.md):
0 commit comments