Pointer to a member function
2017-02-27 23:24
316 查看
Why this post?
Because this looks like magic!Code
// pointer to a member function #include <iostream> using namespace std; class Dog { public: void wag_tail() const { cout << "Tail left. Tail right. Wagging tail!" << endl; } void bark() const { cout << "Barrrrrrrrrrrk!" << endl; } }; int main() { Dog dog; Dog * pdog = & dog; void (Dog::*pfunc)() const = 0; // point pfunc to wag_tail pfunc = Dog::wag_tail; (dog.*pfunc)(); // do NOT leave the first () (pdog->*pfunc)(); // do NOT leave the first () return 0; }
相关文章推荐
- C Pointer-to-Function 与 C++ Pointer-to-MemberFunction 的区别
- C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)
- How do I declare and use a pointer to a class member function?
- C++ 成员函数指针的问题 pointer-to-member-function
- C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)
- Is the type of “pointer-to-member-function” different from “pointer-to-function”?
- C Pointer-to-Function 与 C++ Pointer-to-MemberFunction 的区别
- pointer to function and pointer to member function
- CI3框架初识-控制其使用注意-Call to a member function model() on null in
- Fatal error: Call to a member function table() on a non-object in
- C++中的成员指针(pointer-to-member)
- Fatal error: Call to a member function fetch_array() on a non-object问题的解决办法
- Item 45: Use member function templates to accept "all compatible types."(Effective C++)
- pointer to member
- Fatal error: Call to a member function getSource() on a non-object in G:\wamp\www\ChinaMagicCube\ap
- Drupal8安装:Fatal error: Call to a member function setRecipients()......
- 'static' can indeed be used in C++ to create a Static Member Function
- Fatal error: Call to a member function read() on a non-object in
- Call to member function of non-object: setDebug()
- Fatal error: Call to a member function read() on a non-object in 错误解决方法