I want to implement an interface from my C++/CLI dll in C#. But I am having issues with return value optimization in C++ I guess. Consider
// 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; } }
}
It complains BVNode didn’t implement IBVHNode. My last resort would be to access it via a regular method or using unsafe mode like visual studio suggests:
public TriangleWithNormal* get_Triangle(TriangleWithNormal* t)
{
throw new NotImplementedException();
}
Is there any way to still implement it in property syntax (apart from making TriangleWithNormal a ref class…)?
Update 1 Seems to be that implementing a method TriangleWithNormal GetTriangle() fails for the same reasons. You can however use it like void GetTriangle(TriangleWithNormal%);.
It turned out that the error was gone after I lived some build cycles with my
void GetTriangle(TriangleWithNormal%);workaround. Be it a wonder or more likely a silent clean build, upon commenting in the errorneous property trying to reproduce the error condition one more time, it compiled out of the box.