テンプレートの基本的なビューを取得しようとしていますが、非常に混乱しています。テンプレートに基づいた3つのクラスがあります。
#include <map>
using namespace std;
typedef void (*cb1)(int a, int b);
typedef void (*cb2)(int a, int b, int c);
template <class H>
class CHandle{
H m_id;
};
template <typename H>
class HndFactory {
public:
CHandle<H>* createHandle() {
return new CHandle<H>();
}
};
template <typename H>
CHandle<H> *createHandle(){
CHandle<H> *h = new CHandle<H>();
h->m_id = 100;
return h;
}
template <class S>
class CSubscriber{
S m_proc;
};
template <class H, class S>
class CEvent{
H m_handle;
S m_subscriber;
std::map<CHandle<H>, CSubscriber<S> > m_map;
public:
void subscribe(CHandle<H> *h);
void unsubscribe(CHandle<H> *h);
};
template <class H, class S>
void CEvent<H, S>::subscribe(CHandle<H> *h){
}
int main(void){
HndFactory<int> f;
CSubscriber<cb1> s;
CHandle<int> *h = f.createHandle();
CEvent<CHandle<int>, CSubscriber<cb1> > myevent;
myevent.subscribe(h);
return 0;
}
メソッド " " を実行しようとすると、次のmyevent.subscribe
コンパイラ エラーが発生しました。
CGlue.cpp: In function âint main()â:
CGlue.cpp:64: error: no matching function for call to âCEvent<CHandle<int>, CSubscriber<void (*)(int, int)> >::subscribe(CHandle<int>*&)â
CGlue.cpp:54: note: candidates are: void CEvent<H, S>::subscribe(CHandle<H>*) [with H = CHandle<int>, S = CSubscriber<void (*)(int, int)>]
このメソッドを適切な方法で呼び出すにはどうすればよいですか? オブジェクト '' を作成したときに、h
すでにタイプが定義されていると思いましたか?
よろしく、J.