Function name resolution depending on template parameter

In the test, the following task was performed:

#include <iostream> using namespace std;

template<typename T> void adl(T) {   cout << "T"; }

struct S { };

template<typename T> void call_adl(T t) {   adl(S());   adl(t); }

void adl(S) {   cout << "S"; }

int main () {   call_adl(S()); }

The question is what functions will be called. There is also an explanation that the name of a function that is independent of the template argument is resolved during template definition, while the name of those that depend on the template argument is resolved when the template argument is known. Well, what's the difference between these "times"?

+4
source share
1 answer

Good question. First, he will choose the version of the template, and the second version - without the template. [Live example]

The reason is because, as the explanation explains, in this expression:

adl(S());

adl , . , adl(S) . .

:

adl(t);

, T ( T). , T. main adl(S). .

+5

All Articles