pointer-to-member

What are the Pointer-to-Member ->* and .* Operators in C++?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 04:39:05
问题 Yes, I\'ve seen this question and this FAQ (wrong link) this FAQ, but I still don\'t understand what ->* and .* mean in C++. Those pages provide information about the operators (such as overloading), but don\'t seem to explain well what they are . What are ->* and .* in C++, and when do you need to use them as compared to -> and . ? 回答1: I hope this example will clear things for you //we have a class struct X { void f() {} void g() {} }; typedef void (X::*pointer)(); //ok, let's take a

How can I pass a member function where a free function is expected?

感情迁移 提交于 2019-11-26 00:46:21
问题 The question is the following: consider this piece of code: #include <iostream> class aClass { public: void aTest(int a, int b) { printf(\"%d + %d = %d\", a, b, a + b); } }; void function1(void (*function)(int, int)) { function(1, 1); } void test(int a,int b) { printf(\"%d - %d = %d\", a , b , a - b); } int main (int argc, const char* argv[]) { aClass a(); function1(&test); function1(&aClass::aTest); // <-- How should I point to a\'s aClass::test function? return 0; } How can I use the a \'s

How can I pass a member function where a free function is expected?

此生再无相见时 提交于 2019-11-25 20:35:22
The question is the following: consider this piece of code: #include <iostream> class aClass { public: void aTest(int a, int b) { printf("%d + %d = %d", a, b, a + b); } }; void function1(void (*function)(int, int)) { function(1, 1); } void test(int a,int b) { printf("%d - %d = %d", a , b , a - b); } int main (int argc, const char* argv[]) { aClass a(); function1(&test); function1(&aClass::aTest); // <-- How should I point to a's aClass::test function? return 0; } How can I use the a 's aClass::test as an argument to function1 ? I'm stuck in doing this. I would like to access a member of the