Hi
On Mon, Jan 18, 2010 at 10:37:34PM +1300, Simon Hill wrote:
> http://www.gamedev.net/community/forums/topic.asp?topic_id=559287
>
> SOURCE
> ================================
> 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).
> }
> ===============================
>
> It seems to me now that this is a bug with GCC.
> Can someone confirm this please?
Well, I think g++ behaves correctly. As I understand the standard,
the normal function foo(int) can't be used in the template "bar",
because it is only declared afterwards. In "main", when foo is called
directly, that's no problem: there, foo<pType> and foo(int) are both
declared already. If you write:
te <typename pTYPE>
void foo(pTYPE arg)
{ arg.nid(); }
void foo(int)
{}
template <typename pTYPE>
void bar()
{
pTYPE var;
foo(var);
}
int main()
{
int i;
foo(i);
bar<int>();
}
it compiles fine for me.
However, I'm not absolutely sure what the "correct" behaviour according
to the C++-standard would be.
Axel