Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Get this example to work with member functions?

Reply
Thread Tools

Get this example to work with member functions?

 
 
JohanS
Guest
Posts: n/a
 
      08-23-2004
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 ?
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      08-23-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get UDP example to work Paul Barry Python 7 07-26-2009 10:49 PM
Adding a Check Box Column to a DataGrid - Cannot get example to work (ASP.NET & C#) sianan ASP .Net 1 11-08-2005 07:37 PM
Help! Can't get the FXRuby clipboard example to work... Abe Vionas_MailingList Ruby 4 10-05-2004 08:27 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM
Can't get Sams example to work (re-opening file) Arfur Million C++ 2 12-21-2003 08:29 AM



Advertisments