In some languages (PHP and JavaScript come to mind), I can use a variable as a function. For example:
PHP: Class::$var_function();
Is it possible to this in C++ in a way that doesn’t require a switch or if statement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
James’ answer is probably the best. But, if you’re using a c++11 compatible compiler, you can alternately use std::function
For example:
And a boost version (I’ve never used this so it may be wrong):