Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Function pointers & template functions

Reply
Thread Tools

Function pointers & template functions

 
 
DaKoadMunky
Guest
Posts: n/a
 
      07-23-2004
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.

 
Reply With Quote
 
 
 
 
Jonathan Turkanis
Guest
Posts: n/a
 
      07-23-2004

"DaKoadMunky" <> wrote in message
news:...

> <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


 
Reply With Quote
 
 
 
 
DaKoadMunky
Guest
Posts: n/a
 
      07-23-2004
>Compiles fine for me. Perhaps you are using version 7.0?

7.0.9466 dated 2002.


 
Reply With Quote
 
Jonathan Turkanis
Guest
Posts: n/a
 
      07-23-2004

"DaKoadMunky" <> wrote in message
news:...
> >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


 
Reply With Quote
 
Harald Deischinger
Guest
Posts: n/a
 
      07-23-2004
(DaKoadMunky) wrote in message news:<>...

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
overloading non-template member functions with template member functions Hicham Mouline C++ 1 04-24-2009 07:47 AM
overloading non-template member functions with template member functions Hicham Mouline C++ 0 04-23-2009 11:42 AM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57