私は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();
}
しかし、コンパイルすると、次の2つのエラーが表示されます。
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.
私の質問は次のとおりです:
- このコードで何が間違っているのですか?
- オブジェクトポインタの作り方は?
- クラスのメンバー関数へのポインタを作成する方法とそれらを使用する方法は?
これらの概念を説明してください。