Original Post
I'm overloading a function foo(), then calling a function bar() defined between the original definition of foo() and the overloaded definition of foo(). bar() calls foo(). Unfortunately, even though the call to bar() is after the overload of foo(), bar() chooses the first version of foo(). Yet bar() is able to see the overload of foo() (proven by removing the original definition of foo(), then successfully compiling) Placing the overload of foo() above the definition of bar() also fixes things. G++: Is there something going on here that I don't understand? Does this compile OK for other people? Specs: G++ (4.5.0 20091003) Ubuntu 9.04 (x86-64) Edit: Tags & Problem.
template <typename pTYPE>
void foo(pTYPE arg)
{ arg.nid(); }
template <typename pTYPE>
void bar()
{
pTYPE var;
foo(var);
}
void foo(int)
{}
int main()
{
int i;
foo(i); // OK: Resolves foo(int).
bar<int>(); // ERROR: Fails to resolve foo(int).
}
.cpp: In function 'void foo(pTYPE) [with pTYPE = int]':
.cpp:9:5: instantiated from 'void bar() [with pTYPE = int]'
.cpp:19:14: instantiated from here
.cpp:3:5: error: request for member 'nid' in 'arg', which is of non-class type 'int'