原生C ++“a.h”:
#include <thread>
class a
{
//...
private:
// ...
std::mutex mutex;
};
C ++ / CLI:
#include "a.h" // error cause thread is included
我的解决方案:
原生C ++“a.h”:
class a
{
a();
~a();
//...
private:
// ...
void* mutex;
};
“a.cpp”
#include <thread>
a::a()
{
mutex = new std::mutex;
}
~a::a()
{
delete mutex;
}
C ++ / CLI:
#include "a.h" // no error
答案 0 :(得分:-1)
模板随时为您提供帮助!
A.H:
template <class MutextType>
class a
{
//...
private:
// ...
MutextType mutex;
};
然后,在你的主要或任何地方:
#inculde <thread>
//...
a<std::mutex> instance;
如果您愿意,还可以使用using语句进行清理,以获得更清晰的代码:
#inculde <thread>
//...
using MutexA = a<std::mutex>;
//...
MutexA instance;