[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

pointer to SPECIALIZED member function template not legal c++ ?

Ingo

10/19/2008 9:29:00 PM

Hi,

the following code:


template< typename objectT
, typename worldT >
void(objectT::* getInvocationFunctionFor( objectT* v ))(worldT&)
{
return &(objectT::custom_func/*<worldT>*/);
}

will work unless I activate the commented template arg.

Only exception is VC++, but GCC 4.x and Comeau won't take it.

I would like to know, whether there is a good reason for making this
illegal and whether somebody knows a nice workaround. Or did I do
something stupid here?

Ingo
3 Answers

acehreli

10/19/2008 10:49:00 PM

0

On Oct 19, 2:29 pm, Ingo <Ingo.Nol...@recurdyn.de> wrote:

> template< typename objectT
>                                 , typename worldT >
> void(objectT::* getInvocationFunctionFor( objectT* v ))(worldT&)
> {
>         return &(objectT::custom_func/*<worldT>*/);
>
> }

I recommend using typedef's to make the code readable. I can only fool
myself to think what the return type possibly is. Still, your problem
may be that you are missing a 'template' keyword as in:

return &(objectT::template custom_func<worldT>);

Without that, the compiler would take '<' as the "less than" operator.

Ali

Ingo

10/20/2008 4:47:00 AM

0


>
> I recommend using typedef's to make the code readable. I can only fool
> myself to think what the return type possibly is. Still, your problem

Could you tell me how to do that??

The return type is a pointer to a member function. The argument of
that member function depends on functions actual template arguments.
Since there is no templated typedef, how would you use a typedef in
this situation?

> may be that you are missing a 'template' keyword as in:
>
>    return &(objectT::template custom_func<worldT>);
>
> Without that, the compiler would take '<' as the "less than" operator.
>

Thank you,
this did it. Should have been obvious to me. I just spend too much
time coding with vc.

Ingo

> Ali

Hendrik Schober

10/20/2008 7:36:00 PM

0

Ingo wrote:
>> I recommend using typedef's to make the code readable. I can only fool
>> myself to think what the return type possibly is. Still, your problem
>
> Could you tell me how to do that??
>
> The return type is a pointer to a member function. The argument of
> that member function depends on functions actual template arguments.
> Since there is no templated typedef, how would you use a typedef in
> this situation?

The common workaround is to use a traits class.

> [...]

Schobi