Connecting Tech Pros Worldwide Forums | Help | Site Map

templates and function pointers

Andy White
Guest
 
Posts: n/a
#1: Oct 20 '05
If I want a pointer to a function that returns void and takes as it's
arguments a pointer to a templatized type and a const int, does this need to
be declaired in global scope? I'm not sure of the syntax with the template
part..

template <class T>
void (*f)(T *, const int);

thanks.



Kai-Uwe Bux
Guest
 
Posts: n/a
#2: Oct 20 '05

re: templates and function pointers


Andy White wrote:
[color=blue]
> If I want a pointer to a function that returns void and takes as it's
> arguments a pointer to a templatized type and a const int, does this need
> to be declaired in global scope? I'm not sure of the syntax with the
> template part..
>
> template <class T>
> void (*f)(T *, const int);
>
> thanks.[/color]

Do you want to declare a type or a variable? Anyway, neither templated
typedefs nor templated variables exist. What about:

template < typename T >
struct xxx {

typedef void (*T_function)( T*, int );

};

int main ( void ) {
xxx<int>::T_function f;
}



Best

Kai-Uwe Bux
Andy White
Guest
 
Posts: n/a
#3: Oct 20 '05

re: templates and function pointers



"Kai-Uwe Bux" <jkherciueh@gmx.net> wrote in message
news:dj78de$f3b$1@murdoch.acc.Virginia.EDU...[color=blue]
> Andy White wrote:
>[color=green]
>> If I want a pointer to a function that returns void and takes as it's
>> arguments a pointer to a templatized type and a const int, does this need
>> to be declaired in global scope? I'm not sure of the syntax with the
>> template part..
>>
>> template <class T>
>> void (*f)(T *, const int);
>>
>> thanks.[/color]
>
> Do you want to declare a type or a variable? Anyway, neither templated
> typedefs nor templated variables exist. What about:
>
> template < typename T >
> struct xxx {
>
> typedef void (*T_function)( T*, int );
>
> };
>
> int main ( void ) {
> xxx<int>::T_function f;
> }
>
>
>
> Best
>
> Kai-Uwe Bux[/color]

That works great, thanks.


Closed Thread