Reputation: 27
#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?
Upvotes: 2
Views: 150
Reputation: 188
The GNU C++ compilers as of version 4.7 and beyond, no longer perform some extra unqualified lookups it had performed in the past, namely dependent base class scope lookups and unqualified template function lookups. (Read more)
This can be temporarily worked around by using -fpermissive.
Upvotes: 0
Reputation: 137315
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.
Upvotes: 4