使用std :: mutex关闭头文件的clr选项 [英] Turn off clr option for header file with std::mutex
问题描述
我有一个Visual Studio项目,其中包含带有托管代码的文件和带有非托管代码的文件。该项目具有CLR支持,但是当我在不需要.NET的位置添加文件时,只需右键单击文件即可关闭/ crl选项:
I have a Visual Studio project that contains files with managed code and files with unmanaged code. The project has the CLR support, but when I add a file where I do not need .NET I simply turn off the /crl option with a right-click on the file:
我添加了一个必须包含非托管代码并使用std :: mutex的类。
I added a class that has to contain unmanaged code and use std::mutex.
// Foo.h
class Foo
{
std::mutex m;
}
编译后出现以下错误:
错误C1189:#error:使用
/ clr或/ clr:pure编译时不支持。
error C1189: #error : is not supported when compiling with /clr or /clr:pure.
问题是我没有选择关闭头文件(.h)的clr,因为这是当我右键单击.h文件时的窗口:
The problem is that I do not have the option to turn off the clr for header files (.h), since this is the window when i right-click on a .h file:
如何解决此问题?
推荐答案
可以使用解决方法被称为指向实现(pImpl)的习惯用法。
There is the possibility to use the workaround known as the Pointer To Implementation (pImpl) idiom.
以下是一个简单的示例:
Following is a brief example:
// Foo.h
#include <memory>
class Foo
{
public:
Foo();
// forward declaration to a nested type
struct Mstr;
std::unique_ptr<Mstr> impl;
};
// Foo.cpp
#include <mutex>
struct Foo::Mstr
{
std::mutex m;
};
Foo::Foo()
: impl(new Mstr())
{
}
这篇关于使用std :: mutex关闭头文件的clr选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!