public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* address of overloaded function with no contextual type information
@ 2010-08-11 21:09 Adam Burr
  2010-08-11 21:45 ` Tiago Maluta
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Burr @ 2010-08-11 21:09 UTC (permalink / raw)
  To: gcc-help

Does anyone know what I'm doing wrong here?


#include <iostream>

template< typename T >
struct thingA
{
    template< int I >
    static int doA () {return I;}

    struct thingB
    {
        void doB ()
        {
            // this line does not compile:
            int (*doAPtr) () = &thingA< T >::doA< 2 >;
            std::cerr << (*doAPtr) () << std::endl;
        }
    };
};

int main (int, char **)
{
    thingA< int >::thingB a;
    a.doB ();
}


This is a contrived example but in the "real world" I do need to get a 
pointer to a static template function inside a template class like this.


Here is the gcc error:

main.cc: In member function 'void thingA<T>::thingB::doB()':
main.cc:14: error: expected primary-expression before ';' token
main.cc: In member function 'void thingA<T>::thingB::doB() [with T = int]':
main.cc:23:   instantiated from here
main.cc:14: error: address of overloaded function with no contextual 
type information


Any help is appreciated.

Thanks,
Adam Burr
Blue Sky Studios

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: address of overloaded function with no contextual type  information
  2010-08-11 21:09 address of overloaded function with no contextual type information Adam Burr
@ 2010-08-11 21:45 ` Tiago Maluta
  2010-08-11 21:50   ` Adam Burr
  0 siblings, 1 reply; 5+ messages in thread
From: Tiago Maluta @ 2010-08-11 21:45 UTC (permalink / raw)
  To: Adam Burr; +Cc: gcc-help

Hi Adam,

Change the line:
>           int (*doAPtr) () = &thingA< T >::doA< 2 >;

To:
int (*doAPtr)() = &thingA< int >::doA< 2 >;

--tm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: address of overloaded function with no contextual type  information
  2010-08-11 21:45 ` Tiago Maluta
@ 2010-08-11 21:50   ` Adam Burr
  2010-08-11 21:57     ` Tiago Maluta
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Burr @ 2010-08-11 21:50 UTC (permalink / raw)
  To: Tiago Maluta; +Cc: gcc-help

Tiago Maluta wrote:
> Hi Adam,
>
> Change the line:
>   
>>           int (*doAPtr) () = &thingA< T >::doA< 2 >;
>>     
>
> To:
> int (*doAPtr)() = &thingA< int >::doA< 2 >;
>
> --tm
>   
Yes, that works but it isn't what I need. Luckily I just figured it out! 
That line should be:

int (*doAPtr) () = &thingA< T >::template doA< 2 >;




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: address of overloaded function with no contextual type  information
  2010-08-11 21:50   ` Adam Burr
@ 2010-08-11 21:57     ` Tiago Maluta
  2010-08-11 22:08       ` Adam Burr
  0 siblings, 1 reply; 5+ messages in thread
From: Tiago Maluta @ 2010-08-11 21:57 UTC (permalink / raw)
  To: Adam Burr; +Cc: gcc-help

On Wed, Aug 11, 2010 at 9:50 PM, Adam Burr <adamb@blueskystudios.com> wrote:
> Tiago Maluta wrote:
>>
>> Hi Adam,
>>
>> Change the line:
>>
>>>
>>>          int (*doAPtr) () = &thingA< T >::doA< 2 >;
>>>
>>
>> To:
>> int (*doAPtr)() = &thingA< int >::doA< 2 >;
>>
>
> Yes, that works but it isn't what I need. Luckily I just figured it out!
> That line should be:
>
> int (*doAPtr) () = &thingA< T >::template doA< 2 >;
>
>

I dind't know that construction, thanks.

--tm

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: address of overloaded function with no contextual type  information
  2010-08-11 21:57     ` Tiago Maluta
@ 2010-08-11 22:08       ` Adam Burr
  0 siblings, 0 replies; 5+ messages in thread
From: Adam Burr @ 2010-08-11 22:08 UTC (permalink / raw)
  To: Tiago Maluta; +Cc: gcc-help

Tiago Maluta wrote:
> On Wed, Aug 11, 2010 at 9:50 PM, Adam Burr <adamb@blueskystudios.com> wrote:
>   
>> Tiago Maluta wrote:
>>     
>>> Hi Adam,
>>>
>>> Change the line:
>>>
>>>       
>>>>          int (*doAPtr) () = &thingA< T >::doA< 2 >;
>>>>
>>>>         
>>> To:
>>> int (*doAPtr)() = &thingA< int >::doA< 2 >;
>>>
>>>       
>> Yes, that works but it isn't what I need. Luckily I just figured it out!
>> That line should be:
>>
>> int (*doAPtr) () = &thingA< T >::template doA< 2 >;
>>
>>
>>     
>
> I dind't know that construction, thanks.
>
> --tm
>   

Thanks to John Love-Jensen:

http://gcc.gnu.org/ml/gcc-help/2006-04/msg00023.html

(Sorry for not finding it before posting, I thought I had searched 
exhaustively.)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-08-11 22:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11 21:09 address of overloaded function with no contextual type information Adam Burr
2010-08-11 21:45 ` Tiago Maluta
2010-08-11 21:50   ` Adam Burr
2010-08-11 21:57     ` Tiago Maluta
2010-08-11 22:08       ` Adam Burr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).