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
description: "Learn about the causes of Compiler error C7510 and how to fix it."
3
+
title: "Compiler Error C7510"
4
+
ms.date: 04/21/2021
5
+
f1_keywords: ["C7510"]
6
+
helpviewer_keywords: ["C7510"]
7
+
---
8
+
# Compiler Error C7510
9
+
10
+
> '*type-name*': use of dependent template name must be prefixed with 'template'\
11
+
> '*type-name*': use of dependent type name must be prefixed with 'typename'
12
+
13
+
In [`/permissive-`](../../build/reference/permissive-standards-conformance.md) mode, the compiler requires the **`template`** keyword to precede a template name when it comes after a dependent [`nested-name-specifier`](../../cpp/scope-resolution-operator.md). Similar rules hold for types qualified by **`typename`**.
14
+
15
+
## Remarks
16
+
17
+
Compiler behavior has changed starting in Visual Studio 2017 version 15.8 under [`/permissive-`](../../build/reference/permissive-standards-conformance.md) mode. The compiler requires the **`template`** or **`typename`** keyword to precede a template or type name when it comes after a dependent *`nested-name-specifier`*. For more information, see [Name resolution for dependent types](../../cpp/name-resolution-for-dependent-types.md) and [Templates and name resolution](../../cpp/templates-and-name-resolution.md).
18
+
19
+
## Examples
20
+
21
+
The following code under [`/permissive-`](../../build/reference/permissive-standards-conformance.md) mode now raises C7510:
22
+
23
+
```cpp
24
+
template<typename T> structBase
25
+
{
26
+
template<class U> void example() {}
27
+
};
28
+
29
+
template<typename T>
30
+
structX : Base<T>
31
+
{
32
+
void example()
33
+
{
34
+
Base<T>::example<int>(); // C7510: 'example': use of dependent
35
+
// template name must be prefixed with 'template'
36
+
// note: see reference to class template instantiation
37
+
// 'X<T>' being compiled
38
+
}
39
+
};
40
+
```
41
+
42
+
To fix the error, add the **`template`** keyword to the `Base<T>::example<int>();` statement, as shown in the following example:
43
+
44
+
```cpp
45
+
template<typename T> structBase
46
+
{
47
+
template<class U> void example() {}
48
+
};
49
+
50
+
template<typename T>
51
+
structX : Base<T>
52
+
{
53
+
void example()
54
+
{
55
+
// Add template keyword here:
56
+
Base<T>::template example<int>();
57
+
}
58
+
};
59
+
```
60
+
61
+
In Visual Studio 2019 under **`/std:c++latest`**, template function bodies that have **`if constexpr`** statements have extra parsing-related checks enabled. For example, in Visual Studio 2017 the following code produces C7510 only if the **`/permissive-`** option is set. In Visual Studio 2019 the same code raises errors even when the **`/permissive`** option is set:
Copy file name to clipboardExpand all lines: docs/overview/cpp-conformance-improvements-2017.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1785,7 +1785,7 @@ int main()
1785
1785
1786
1786
In [`/permissive-`](../build/reference/permissive-standards-conformance.md) mode, the compiler now requires the **`template`** keyword to precede a template-name when it comes after a dependent nested-name-specifier.
1787
1787
1788
-
The following code in [`/permissive-`](../build/reference/permissive-standards-conformance.md) mode now raises C7510:
1788
+
The following code in [`/permissive-`](../build/reference/permissive-standards-conformance.md) mode now raises [C7510](../error-messages/compiler-errors-2/compiler-error-c7510.md):
Copy file name to clipboardExpand all lines: docs/overview/cpp-conformance-improvements.md
+9-4Lines changed: 9 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -274,16 +274,21 @@ void example()
274
274
275
275
### Function template bodies containing `if constexpr` statements
276
276
277
-
Template function bodies containing **`if constexpr`** statements have some [`/permissive-`](../build/reference/permissive-standards-conformance.md)parsing-related checks enabled. For example, in Visual Studio 2017 the following code produces C7510 only if the **`/permissive-`** option isn't set. In Visual Studio 2019 the same code raises errors even when the **`/permissive-`** option is set:
277
+
In Visual Studio 2019 under **`/std:c++latest`**, template function bodies that have **`if constexpr`** statements have extra parsing-related checks enabled. For example, in Visual Studio 2017 the following code produces [C7510](../error-messages/compiler-errors-2/compiler-error-c7510.md) only if the **`/permissive-`** option is set. In Visual Studio 2019 the same code raises errors even when the **`/permissive`** option is set:
0 commit comments