Function pointers & template functions



 DEVELOP > c-Plus-Plus > Function pointers & template functions

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "DaKoadMunky"
Date: 22 Jul 2004 09:41:16 PM
Object: Function pointers & template functions
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.
.

User: "Jonathan Turkanis"

Title: Re: Function pointers & template functions 22 Jul 2004 10:11:39 PM
"DaKoadMunky" <dakoadmunky@aol.com> wrote in message
news:20040722224116.05710.00002020@mb-m14.aol.com...

<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
.
User: "DaKoadMunky"

Title: Re: Function pointers & template functions 22 Jul 2004 10:12:16 PM

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

7.0.9466 dated 2002.
.
User: "Jonathan Turkanis"

Title: Re: Function pointers & template functions 22 Jul 2004 10:21:28 PM
"DaKoadMunky" <dakoadmunky@aol.com> wrote in message
news:20040722231216.16456.00000263@mb-m14.aol.com...

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


7.0.9466 dated 2002.

7.1 is when it became a first-class compiler.
Jonathan
.



User: "Harald Deischinger"

Title: Re: Function pointers & template functions 23 Jul 2004 06:33:17 AM
(DaKoadMunky) wrote in message news:<20040722224116.05710.00002020@mb-m14.aol.com>...

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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER