Connecting Tech Pros Worldwide Forums | Help | Site Map

taking address of a template method

Domenico Andreoli
Guest
 
Posts: n/a
#1: Jul 19 '05
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

Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 19 '05

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


Domenico Andreoli
Guest
 
Posts: n/a
#3: Jul 19 '05

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