By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Get this example to work with member functions?

P: n/a
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 ?
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
kb******@gascad.at
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.