taking address of a template method

D

Domenico Andreoli

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
 
V

Victor Bazarov

Domenico Andreoli said:
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);

...
}

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
 
D

Domenico Andreoli

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?
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top