移植可能な Thread 抽象化を作成しようとしています。現在、Unix で動作する dn をコンパイルするコードがありますが、Windows ではコンパイルされません (VS2010 を使用)。
class Thread
{
public:
Thread();
~Thread();
template<typename Callable, typename Arg>
void startThread(Callable c, Arg a);
void killThread();
private:
template<typename Bind>
struct nested
{
static DWORD WINAPI run(void *obj)
{
Bind * b = reinterpret_cast<Bind *>(obj);
return (b->exec());
}
};
template<typename Callable, typename Arg>
class Binder
{
public:
Binder(Callable c, Arg a): _call(c), _arg(a) {}
~Binder() {}
DWORD operator()() {return (this->_call(this->_arg))}
DWORD exec() {return (this->_call(this->_arg))}
private:
Callable _call;
Arg _arg;
};
HANDLE _handle;
DWORD _id;
bool _isRunning;
DWORD _exitValue;
};
template<typename Callable, typename Arg>
void Thread::startThread(Callable c, Arg a)
{
Thread::Binder<Callable, Arg> *b =
new Thread::Binder<Callable, Arg>(c, a);
CreateThread(0, 0,
Thread::nested< Thread::Binder<Callable, Arg> >::run,
b, 0, &this->_id);
}
コンパイルしようとすると、VS でエラー C2039 が表示されます。
'nested<Thread::Binder<unsigned long (__cdecl*)(int *),int *> >' : is not a member of 'Thread'
なぜg ++はそれを見ることができますが、VSは見ることができませんか? ほとんどの場合、それはテンプレートの特殊化によるものだと思いますが、どうしてですか?