我想在 C# 中从我的 C++/CLI dll 实现一个接口。但我猜我在 C++ 中的返回值优化有问题。考虑
// BVHTree.cpp:
public value struct Vector3
{
float X, Y, Z;
};
public value struct TriangleWithNormal
{
Vector3 A, B, C, Normal;
};
public interface class IBVHNode
{
property TriangleWithNormal Triangle { TriangleWithNormal get(); } // among others
property bool IsLeaf { bool get(); } // can implement this
};
// BVHNode.cs:
public class BVHNode : IBVHNode // Error: member TriangleWithNormal* IBVHNode.get_Triangle(TriangleWithNormal*) not implemented (sth. along those lines)
{
public TriangleWithNormal Triangle { get { return new TriangleWithNormal(); } }
public bool IsLeaf { get { return true; } }
}
它抱怨BVNode
没有实施IBVHNode
。我最后的手段是通过常规方法或使用 Visual Studio 建议的不安全模式访问它:
public TriangleWithNormal* get_Triangle(TriangleWithNormal* t)
{
throw new NotImplementedException();
}
有没有办法仍然在属性语法中实现它(除了制作TriangleWithNormal
... ref class
)?
更新 1似乎是因为TriangleWithNormal GetTriangle()
同样的原因实现方法失败。但是,您可以像void GetTriangle(TriangleWithNormal%);
.