1

I have a C++/CLI project that references a C# dll, and I need to implement an Interface class.

The interface class in C# looks like this:

public interface IMeshData{
    //(...)        
    INode NodeById(int nodeId);
    double[] NodeXYZById(int nodeId);
}

In the C++ project I can implement this interface:

public ref class IMeshData_class : public IMeshData{

public:
    //this one is accepted:
    virtual INode^ NodeById(int nid){
        return this->NodeById(nid);
    }
    //this one gives me an error:
    virtual double*  NodeXYZById(int nid){
         return this->NodeXYZById(nid);
    }
}

When I first define my class above without any member function, I get the error:

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

So after defining the function NodeById, this error goes away, and I get:

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

NodeXYZById return a double[], I thought this would translate to a double* in C++, but it doesn't seem to be the case.

How should I correctly implement a C# member function in C++ which returns an array?

3
  • 2
    My C++/CLI is very rusty, but I think there was an array<double>^ for exactly that. Commented Jul 18, 2018 at 7:23
  • @TanveerBadar Great, that worked perfectly it seems, thanks. (If you make an answer, I'll accept it as a solution). Commented Jul 18, 2018 at 7:27
  • Posted as answer too. Commented Jul 19, 2018 at 10:16

1 Answer 1

1

As commented above, in C++/CLI you have to use the type array<T>^ in place of what might be T[] in C#.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.