我是新來的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