开发者

Exposing unmanaged types in managed code

I have two unmanaged clas开发者_开发问答ses, in two different DLLs:

class A
{
public:
void doSomething();
private:
int x;
}

class B
{
public:
void doSomethingToAnA(A*);
}

and I want to wrap them both in managed C++, so naturally:

ref class managedA
{
public:
void doSomething();
private:
A* unmanagedA;
}

ref class managedB
{
public:
void doSomethingToAnA(managedA*);
private:
B* unmanagedB;
}

so doSomethingToAnA(managedA*) should probably look like this:

void managedB::doSomethingToAnA(managedA* a)
{
unmanagedB->doSomethingToAnA(a->unmanagedA);
}

however, unmanagedA is private. I don't want to change its visibility or create a getter for it because then a C# user will also be able to see it (which is very strange), plus, it's wrong design-wise. I also can't use private public visibility since the classes are located in different DLLs.

is there a good "textbook" solution for this problem?


The Pimpl Idiom may be applicable here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜