remi
remi

Reputation: 1047

Inherit from C# interface to class in C++/CLI project

My C++/CLI dll project refers to a C# dll. I'm able to use all the classes defined in the refered dll, but I'm unsure how to handle Interfaces.

By reading other questions online, I believe I should be able to create a class which inherits from the interface.

If the interface is called IMeshData and I define a class MeshData, isn't this correct?:

public ref class MeshData : IMeshData{

     //Here I should be able to implement my own functions which can access the interface function, or overload them.

}

In Visual Studio, if I do the above, I will get an error on MeshData stating:

Error: class fails to implement interface function "IMeshData::NodeById" (declared in (...).dll)

The function IMeshData::NodeById is defined as:

INode IMeshData.NodeById(Int32 nodeId)

Where INode is a different interface.

Does that error mean that this function NodeById, can for reason not be implemented, and therefor I'm cannot inherit any functions?

How would I implement this function (which I do not need), so that this error will be resolved?

I do not have access the source of the refered dll.

Upvotes: 0

Views: 950

Answers (1)

remi
remi

Reputation: 1047

Here is how I fixed it, with courtesy to the comments above:

public ref class MeshData : IMeshData{
    public:
         virtual INode^ NodeById(int){throw gcnew NotImplementedException;}
}

(That solved the error message I mentioned in the question, but now it is telling me the same thing about another function. So this will probably have to be repeated.)

Upvotes: 2

Related Questions