shared_ptr包括托管代码时未定义 [英] shared_ptr not defined when including from managed code

查看:822
本文介绍了shared_ptr包括托管代码时未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在非托管C ++静态库中编写一个托管包装器(C ++ / CLI),并且有两个问题:


  1. 非托管库在其头中使用 std :: shared_ptr < memory> ,并且标题作为非托管项目的一部分编译。但是,当我在受管项目中包含此标题时,我收到此错误:



    错误C2039:'shared_ptr':不是'std' > c> c> c $>

  2. / 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:

  1. 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'

  2. How do I access the Values collection of a SortedDictionary<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆