我是 c++ 新手。我想了解对象指针和指向成员函数的指针。我写了如下代码:
代码 :
#include <iostream>
using namespace std;
class golu
{
int i;
public:
void man()
{
cout<<"\ntry to learn \n";
}
};
int main()
{
golu m, *n;
void golu:: *t =&golu::man(); //making pointer to member function
n=&m;//confused is it object pointer
n->*t();
}
但是当我编译它时,它向我显示了以下两个错误:
pcc.cpp: In function ‘int main()’:
pcc.cpp:15: error: cannot declare pointer to ‘void’ member
pcc.cpp:15: error: cannot call member function ‘void golu::man()’ without object
pcc.cpp:18: error: ‘t’ cannot be used as a function.
我的问题如下:
- 我在这段代码中做错了什么?
- 如何制作对象指针?
- 如何使指向类的成员函数的指针以及如何使用它们?
请解释我这些概念。