tags:

views:

67

answers:

3

The line of code i need to translate from C++ to C#:

void GetAnalysisModeName( ON_wString& name ) const;

I've tried with:

public override void GetAnalysisModeName(string name){}

But it tells me that the return type has to be a string.

+1  A: 

If the function you are overloading returns a string your function must return a string. If you have no underlying function remove the override from the declaration.

rerun
+1  A: 

Is this what you are looking for?

public void GetAnalysisModeName(ref string name){}

The ref keyword has a similar meaning to the C++ &: it indicates a reference parameter.

But importantly, who / what is telling you that the return type has to be a string?

Ani
Visual Studio Express, i get a warning telling me that the return type has to be string.
Bildsoe
Can you give us some more information on what you mean by "translate C++ to C#"? What is the compiler checking the 'expected' signature against?
Ani
+5  A: 

A straight conversion would be:

public void GetAnalysisModeName(ref string name)
{
}

But it looks like you're also trying to override something inside of the C# class.

Judging by the message that the return type must be a string, I'd say that the signature of the method you are overriding and the signature of the C++ method you posted don't match.

EDIT

This is actually a mis-understanding. I double checked the Rhino APIs. You're using the .NET SDK. Your C++ example uses the C++ SDK. The two SDKs have different signatures. For you to properly override the .NET version, you need:

public string GetAnalysisModeName(){ }

I suggest you download the .NET SDK Documentation for Rhino so that you have it as a reference. It will also give you a brief description of what the method is supposed to do when implemented.

Justin Niessner
I'm creating my own analysisMode and doing so overriding its methods. The GetAnalysisMode, should just do what it usually does. Which i don't know what is because, i don't have access to the original method.
Bildsoe
I get the following error 'kineticMold.customAnalysis' does not implement inherited abstract member RMA.Rhino.MRhinoVisualAnalysisMode.GetAnalysisModeName()'
Bildsoe
@Bildsoe - Is the analysisMode class a C# class?
Justin Niessner
@Justin - Yes it is. I have an example in C++ i'm translating from C++ to C# and the class has an C++ implementation CRhinoAnalysisMode and a .Net MRhinoAnalysisMode
Bildsoe
@Bildsoe - I'm assuming you're using the C# SDK?
Justin Niessner
@Justin - Yes i'm using the C# SDK. The documentation states the following: Get the name of the analysis mode. This name is used by the What command and the object properties details window to describe the object. C#public System::String GetAnalysisModeName();Visual BasicPublic Function GetAnalysisModeName() As System::String
Bildsoe
@Justin - Or actually what i don't get is what to turn this :void GetAnalysisModeName( ON_wString into. I've done overrides previously, but i can't see from the C++ code, what im supposed to return.
Bildsoe
@Bildsoe - Do you have the source for the C++ method? It's passing name by reference to the method which means no return value is necessary. The original name variable will hold the last value assigned to it by the GetAnalysisModeName method.
Justin Niessner
@Justin - But as you wrote in your edit, the correct form was: public string GetAnalysisModeName(){ }. Doesn't this require a return, as no reference is being passed?
Bildsoe
The C++ SDK version of the method and the C# version of the method have two different signatures. The C++ version takes a parameter by reference. The C# version returns the string instead. Whatever value was assigned to the name parameter in the C++ version is what you should return in the C# version.
Justin Niessner
@Justin - Ahh ok, i'll do that then.
Bildsoe