C ++ / CLI workaround to implement C ++ interface

Micropather requires users to implement their abstract Graph class in order to use the library. What's a good way to do this from C ++ / CLI so that I can use Micropather in .NET?

There are only two methods:

virtual float LeastCostEstimate( void* stateStart, void* stateEnd ) = 0;
virtual void AdjacentCost( void* state, std::vector< StateCost > *adjacent ) = 0;

      

So far I've been intriguing with gcroot and delegates, but I don't have anything solid yet.

+2


source to share


1 answer


Just write a regular C ++ class that inherits Graph

and use the gcroot template to reference CLR objects from that class.



class MyGraph : public Graph
{
    gcroot<SomethingImportant ^> _stuff;

    // implement abstract memfuncs to call onto _stuff
};

      

+2


source







All Articles