E2105 'template' qualifier must specify a member template name (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Compiler Errors And Warnings (C++) Index

When parsing code that depends in some way upon a template parameter, it is sometimes impossible to know whether a member name will resolve to a template function name, or a regular parameter. In the following code, a 'template' qualifier is required in order to know if the '<' (less-then) operator should be parsed as the beginning character of a template argument list, or as a regular less-than operator:

template<class T>
void foo(T a)
{
a.member<10>();
}

Although it may be apparent to the reader what is meant, the compiler does not know that "member" refers to a member template function, and it will parse the line of code as follows:

a.member < (10>());

In order to tell the compiler that the less-than character begins a template argument list, the 'template' qualifier is needed:

a.template member<10>();   // "member" must be a member template

If the 'template' qualifier is used in a situation where "member" does not resolve to a member template, the above error will result.