我是新来的C++。我想知道对象指针和成员函数的指针。我写了这以下代码: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.
我的问题是以下几点:
- 我在这段代码中做错了什么?
- 如何制作对象指针?
- 如何使指针指向一个类的成员函数以及如何使用它们?
请给我解释一下这些概念。
将您简要介绍一下先决?我不了解这方面的优先权概念。 – Golu 2011-06-07 08:53:36
是否修改回答适合你? – AProgrammer 2011-06-07 08:56:48
请告诉我先决。 – Golu 2011-06-07 09:15:48