#include <iostream>
template<typename T>
void f(T x)
{
g(x); // g is a dependent name
};
void g(int a)
{
std::cout << a;
}
int main()
{
int a = 12;
f(a);
}
//this should be point of declaration for f<int>
Above code gives compilation error "‘g’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation".
Since g is a dependent name, its name should be visible at the time of instantiation. Please tell what am I missing?
The lookup in the instantiation context only considers candidates found by argument-dependent lookup. Since int
has no associated namespaces or classes, that lookup finds nothing.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments