从托管代码包含时未定义shared_ptr
我正在尝试围绕非托管 C++ 静态库编写托管包装器 (C++/CLI),但遇到两个问题:
非托管库在其标头中使用
std::shared_ptr
。包含
,并且标头作为非托管项目的一部分进行编译。但是,当我在托管项目中包含此标头时,我收到此错误:错误 C2039:“shared_ptr”:不是“std”的成员
How do I access the
Values
collection of来自 C++/CLI 的SortedDictionary
?我似乎找不到任何正确语法的示例,并且 C# 样式语法无法编译。
#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'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);
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Shared_ptr 存在于
<内存>
中,而不是<功能>
中。使其看起来类似于:第二个问题(请只问一个):
shared_ptr lives in
<memory>
not<functional>
. Make it look similar to this:Second question (ask only one please):
我在这里找到了答案:在 Visual Studio 中编辑 $(IncludePath) "macro" 2010
Visual Studio 2010 包含 Visual Studio 2008 中的标头,该标头没有
shared_ptr
。确切的分辨率描述
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 tovs100
resolved the issue.