从托管代码中包含时,未定义shared_ptr

Dar*_*con 4 c++-cli visual-studio-2010 shared-ptr

我正在尝试围绕非托管C++静态库编写托管包装器(C++/CLI),并且遇到两个问题:

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

    错误C2039:'shared_ptr':不是'std'的成员

  2. 如何从C++/CLI 访问Values集合SortedDictionary<K, V>?我似乎无法找到正确语法的任何示例,并且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);
    };
}
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 6

shared_ptr <memory>不在<functional>.使它看起来类似于:

#pragma managed(push, off)
#include <memory>
#include "yourUnmanagedLibrary.h"
#pragma managed(pop)
Run Code Online (Sandbox Code Playgroud)

第二个问题(请问一个请):

using namespace System::Collections::Generic; 
...
    SortedDictionary<int, String^>^ coll = gcnew SortedDictionary<int, String^>;
    coll->Add(1, "one");
    coll->Add(0, "zero");
    for each (String^ value in coll->Values) {
        Console::WriteLine(value);
    }
Run Code Online (Sandbox Code Playgroud)