Connecting Tech Pros Worldwide Help | Site Map

taking address of a template method

  #1  
Old July 19th, 2005, 05:18 PM
Domenico Andreoli
Guest
 
Posts: n/a
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, 05:18 PM
Victor Bazarov
Guest
 
Posts: n/a

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, 05:19 PM
Domenico Andreoli
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding temporary objects / taking address Henning Hasemann answers 17 June 30th, 2006 10:25 AM
State of Dynamically Created controls on PostBack? Amelyan answers 5 November 19th, 2005 01:31 PM
Example of calling JAMA which uses TNT templates jim.brown answers 10 July 22nd, 2005 10:01 AM
Example of calling JAMA which uses TNT templates jim.brown answers 10 July 22nd, 2005 09:32 AM