我有一个围绕 win32/pthreads 的 C++ 线程包装类。问题出在我的标题中,我需要大量的 biggie-include,例如 windows.h 和 boost::function,用于在下面声明我的 typedef。
有没有办法解决?我知道您可以转发声明类和结构,但是诸如 win32 HANDLE 之类的数据类型和命名空间中的模板函数...?
#include "boost/function.hpp"
/* Thread wrapper class */
class IThread
{
public:
#if defined _WIN32 || _WIN64
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#undef WIN32_LEAN_AND_MEAN
typedef HANDLE ThreadHandle;
#else
#include <pthread.h>
typedef pthread_t ThreadHandle;
#endif
enum ThreadState
{
DETACHED = 0,
RUNNING,
FINISHED
};
typedef boost::function1<void, void*> Task;
virtual ~IThread() { }
IThread& operator=(IThread& other);
virtual int32_t Join() = 0;
virtual int32_t SetPriority(int32_t priority) = 0;
virtual ThreadHandle& GetNativeHandle() = 0;
virtual ThreadState GetThreadState() const = 0;
};
谢谢