Connecting Tech Pros Worldwide Help | Site Map

taking address of a template method

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 04:18 PM
Domenico Andreoli
Guest
 
Posts: n/a
Default taking address of a template method

hello,

i have the following problem: taking the pointer of a particular
instantiation of template member function A::f. i have no idea of how
achieve in the intent. :(

any halp or hint would be very appreciated.

cheers
domenico

struct A
{
template <typename T>
void f(const T& t) { ... }
};

void g(void (A::* f)(const int&))
{
...
}

int main()
{
void (A::* x)(const int&) = &(A::template f<int>);
g(x);

...
}


-----[ Domenico Andreoli, aka cavok
--[ http://filibusta.crema.unimi.it/~cavok/gpgkey.asc
---[ 3A0F 2F80 F79C 678A 8936 4FEE 0677 9033 A20E BC50

  #2  
Old July 19th, 2005, 04:18 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: taking address of a template method

"Domenico Andreoli" <cavok@cavok.dyndns.org> wrote...[color=blue]
> i have the following problem: taking the pointer of a particular
> instantiation of template member function A::f. i have no idea of how
> achieve in the intent. :(
>
> any halp or hint would be very appreciated.
>
> cheers
> domenico
>
> struct A
> {
> template <typename T>
> void f(const T& t) { ... }
> };
>
> void g(void (A::* f)(const int&))
> {
> ...
> }
>
> int main()
> {
> void (A::* x)(const int&) = &(A::template f<int>);
> g(x);
>
> ...
> }[/color]

This:

struct A
{
template <typename T> void f(const T& t) {}
};

void g(void (A::*f)(const int&))
{
A a;
(a.*f)(42);
}

int main()
{
void (A::* x)(const int&) = &A::f<int>;
g(x);
}

compiles for me, as expected.

What error messages do you get, if any?

Victor


  #3  
Old July 19th, 2005, 04:19 PM
Domenico Andreoli
Guest
 
Posts: n/a
Default Re: taking address of a template method

In article <vjht3rq3qbkjdd@corp.supernews.com>, Victor Bazarov wrote:[color=blue]
> This:
>
> struct A
> {
> template <typename T> void f(const T& t) {}
> };
>
> void g(void (A::*f)(const int&))
> {
> A a;
> (a.*f)(42);
> }
>
> int main()
> {
> void (A::* x)(const int&) = &A::f<int>;
> g(x);
> }
>
> compiles for me, as expected.
>
> What error messages do you get, if any?
>[/color]
none. thanks to your confirmation i found it was my fault elsewhere.

i do not even need to explicate the instantiation, compiler guesses it
from the signature of the pointer x.

many thanks again
domenico

-----[ Domenico Andreoli, aka cavok
--[ http://filibusta.crema.unimi.it/~cavok/gpgkey.asc
---[ 3A0F 2F80 F79C 678A 8936 4FEE 0677 9033 A20E BC50
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.