Function pointers & template functions

D

DaKoadMunky

My question relates to storing the addresses of functions generated by
templates in pointers to functions.

<CODE>

template<class T>
void Global() {}

namespace ANamespace
{
template<class T>
void InANamespace() {}
}

int main()
{
void (*fncPtr)() = Global<int>; //Compiles on both Comeau & MSVC++.NET

fncPtr = ANamespace::InANamespace<int>; //Compiles on Comeau but not
MSVC++.NET

return 0;
}

</CODE>

Using MSVC++.NET line 1 compiles but line 2 does not.

Using the Comeau Online compiler @ http://www.comeaucomputing.com/tryitout/
both lines compile.

I am assuming that Comeau is correct, but you know what they say about making
assumptions.

Can anyone comment on the correct syntax and which compiler is correct?

Thanks.
 
J

Jonathan Turkanis

<CODE>

template<class T>
void Global() {}

namespace ANamespace
{
template<class T>
void InANamespace() {}
}

int main()
{
void (*fncPtr)() = Global<int>; //Compiles on both Comeau & MSVC++.NET

fncPtr = ANamespace::InANamespace<int>; //Compiles on Comeau but not
MSVC++.NET

return 0;
}

</CODE>

Using MSVC++.NET line 1 compiles but line 2 does not.

Compiles fine for me. Perhaps you are using version 7.0?

Jonathan
 
H

Harald Deischinger

Using MSVC++.NET line 1 compiles but line 2 does not.
...
Can anyone comment on the correct syntax and which compiler is correct?

I've just tried your code using MSVC 7.1 (compiler version 13.10.3077)
and everything is working fine.

harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top