shared_ptr包括托管代码时未定义 [英] shared_ptr not defined when including from managed code
问题描述
我试图在非托管C ++静态库中编写一个托管包装器(C ++ / CLI),并且有两个问题:
-
非托管库在其头中使用
std :: shared_ptr
。< memory>
,并且标题作为非托管项目的一部分编译。但是,当我在受管项目中包含此标题时,我收到此错误:
错误C2039:'shared_ptr':不是'std' > c> c> c $>
/ code>从C ++ / CLI?我似乎找不到任何正确的语法示例,并且C#-style语法不编译。
代码for#1:
// 1> Dummy.h(10):error C2039:'shared_ptr':不是成员'std'
#pragma once
#pragma managed(push,off)
#include< memory>
class Foo {};
typedef std :: shared_ptr< Foo> FooPtr;
#pragma managed(pop)
使用命名空间System;
命名空间Dummy {
public ref class Class1
{
public:
Class1(FooPtr);
};
}
:编辑$(IncludePath)"宏"在Visual Studio 2010
Visual Studio 2010包括Visual Studio 2008中的标头,它们没有 shared_ptr
。
确切的分辨率描述此处。 常规选项卡上的平台工具集默认为 vs90
。将此更改为 vs100
可解决此问题。
I'm trying to write a managed wrapper (C++/CLI) around an unmanaged C++ static library and am having two problems:
The unmanaged library uses
std::shared_ptr
in its headers.<memory>
is included, and the header compiles as part of an unmanaged project. When I include this header in the managed project, however, I receive this error:error C2039: 'shared_ptr' : is not a member of 'std'
How do I access the
Values
collection of aSortedDictionary<K, V>
from C++/CLI? I cannot seem to find any examples of the proper syntax, and the C#-style syntax does not compile.
Code for #1:
// 1>Dummy.h(10): error C2039: 'shared_ptr' : is not a member of 'std'
#pragma once
#pragma managed(push, off)
#include <memory>
class Foo {};
typedef std::shared_ptr<Foo> FooPtr;
#pragma managed(pop)
using namespace System;
namespace Dummy {
public ref class Class1
{
public:
Class1(FooPtr);
};
}
I have found the answer here: Edit $(IncludePath) "macro" in Visual Studio 2010
Visual Studio 2010 is including the headers from Visual Studio 2008, which do not have shared_ptr
.
The exact resolution is described here. The Platform Toolset on the General tab defaulted to vs90
. Changing this to vs100
resolved the issue.
这篇关于shared_ptr包括托管代码时未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!