Call of Templated Function w/ Explicit Template Argument Fails to Compile

greetings kind regards
may i please enquire why compiler reports error for code below as indicated .
thank you kindly

template<typename T, typename U>
void foo()
{
T _T;
U _U;
_T.aaa<U>(_U); // error
_T.bbb(_U); // no error
ccc<U>(_U); // no error
ddd(_U); // no error
}

int main(){}
Last edited on
The meaning of the name _T.aaa depends on the template parameter T: it could be a template, a typename, or a value. By default, the compiler treats it as if it was a value, and the following < and > as less-than and greater-than operators. There can be ambiguity in certain cases.

If you wish for a dependent name like _T.aaa to be a template or a typename, you must say what you want every time:
_T.template aaa<U>(_U);
The example you gave is not actually ambiguous because U is only ever a typename, but the compiler doesn't care.
Last edited on
Registered users can post here. Sign in or register to post.