3
我有一个关于为在C#中使用的本机C++类创建C++ CLI包装器的问题。C++ CLI包装器
下面是一个例子代码:
#include "stdafx.h"
#pragma once
using namespace System;
namespace Wrapper {
class NativeClass
{
public:
NativeClass() {}
int Add(int a, int b)
{
return a+b;
}
};
public ref class Wrapper
{
public:
Wrapper() {pNative = new NativeClass();}
int Add(int a, int b)
{
return(pNative->Add(a,b));
}
~Wrapper()
{
delete pNative;
pNative = 0;
}
!Wrapper()
{
this->~Wrapper();
}
//My problem is here.
NativeClass* GetNative()
{
return pNative;
}
private:
NativeClass* pNative;
};
}
此代码工作正常。我需要检索指向本地类的指针,以便在其他包装类中使用它。但是,当我使用这个包装类时,我不希望函数“GetNative”在C#中可见。我怎样才能隐藏它?
尝试'内部:'作为访问符。 – Medinoc 2013-04-25 09:47:51
如果其他包装类在同一个程序集中,请使用“internal”而不是“public”。 – 2013-04-25 09:47:54
谢谢。如果他们不在同一个集会中,我该怎么办? (这不是我的情况,我只是想知道,非常感谢) – KooKoo 2013-04-25 10:43:43