Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Get this example to work with member functions? (http://www.velocityreviews.com/forums/t285173-get-this-example-to-work-with-member-functions.html)

JohanS 08-23-2004 02:27 PM

Get this example to work with member functions?
 
template<typename T>
T testFunc( T(*pFunction) (T), T x)
{
return pFunction(x);
}

int print(int i)
{
return i;
}

int main()
{
cout << testFunc(&print , 5) << endl;
return 0;
}

How can i make this work calling a member function instead?
If i have object A with member function int setValue(int);
and i wanna pass &A.setValue ?

Karl Heinz Buchegger 08-23-2004 02:29 PM

Re: Get this example to work with member functions?
 
JohanS wrote:
>
> template<typename T>
> T testFunc( T(*pFunction) (T), T x)
> {
> return pFunction(x);
> }
>
> int print(int i)
> {
> return i;
> }
>
> int main()
> {
> cout << testFunc(&print , 5) << endl;
> return 0;
> }
>
> How can i make this work calling a member function instead?
> If i have object A with member function int setValue(int);
> and i wanna pass &A.setValue ?


See the FAQ

http://www.parashift.com/c++-faq-lit...o-members.html

--
Karl Heinz Buchegger
kbuchegg@gascad.at


All times are GMT. The time now is 09:56 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.