class Thread
{
Sync::TYPE sync; // synchronous start/finish
char name[256]; // thread name
thread handle; // thread handle
HANDLE abort, // abort event handle
start; // start event handle
public:
Thread(const char *desc,Sync::TYPE ctrl,void (*fn)(void *),void *arg=NULL);
Thread(Thread &th);
Thread(void);
~Thread(void);
HANDLE AbortHandle(void) const { return(abort); }
HANDLE StartHandle(void) const { return(start); }
thread::id ID(void) const { return(handle.get_id()); }
void Name(const char *value);
const char *Name(void) const { return(name); }
void Sync(Sync::TYPE value) { sync=value; }
Sync::TYPE Sync(void) const { return(sync); }
thread *ThreadHandle(void) { return(&handle); }
Thread &operator=(Thread &th);
};
class ThreadList
{
map<thread::id,Thread> TiL;
public:
ThreadList(void);
~ThreadList(void);
HANDLE AbortHandle(void);
void Clear(void);
bool Close(thread::id id);
void Close(map<thread::id,Thread>::iterator pos);
map<thread::id,Thread>::iterator Create(char *name,Sync::TYPE sync,void (*function)(void*),void *arg=NULL);
map<thread::id,Thread>::iterator Find(thread::id id) { return(TiL.find(id)); }
int Size(void) const { return(TiL.size()); }
void Start(map<thread::id,Thread>::iterator pos);
HANDLE StartHandle(void);
};
现在此代码生成错误:
map<thread::id,Thread>::iterator ThreadList::Create(char *name,Sync::TYPE sync,void (*function)(void*),void *arg)
{
pair<map<thread::id,Thread>::iterator,bool> result;
thread::id id;
Thread th(name,sync,function,arg);
id=th.ThreadHandle()->get_id();
**result=TiL.insert(make_pair(id,th));**
return(result.first);
}
故障线以粗体显示。确切的错误信息是这样的:
错误 C2664:'std::_Tree_iterator>> std::_Tree>::insert(std::_Tree_const_iterator>>,const std::pair &)':无法将参数 1 从 'std::pair' 转换为 'std: :一对 &&'
我在这里做错了什么?
亲切的问候,瓦迪姆。
PS:对不起,我应该在那一刻澄清。也有这些定义:
Thread::Thread(Thread &th)
{
sync=th.sync;
StrCopy(name,sizeof(name),th.name);
abort=th.abort;
start=th.start;
handle=move(th.handle);
}
Thread &Thread::operator=(Thread &th)
{
sync=th.sync;
StrCopy(name,sizeof(name),th.name);
abort=th.abort;
start=th.start;
handle=move(th.handle);
return(*this);
}