使用std :: mutex关闭头文件的clr选项

编程入门 行业动态 更新时间:2024-10-26 22:26:25
本文介绍了使用std :: mutex关闭头文件的clr选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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选项

本文发布于:2023-11-10 06:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项   头文件   std   mutex   clr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!