1

How should I deal with methods with default arguments when passing the border between C# and C++/CLI?

C# does support default arguments, but C++/CLI does not. That means in C++/CLI I must have two different methods one with the parameter that has default value, and one without which assumes the default value. What about in C#, should I have two separate methods also, or can I get way with one, and then the propagation to C++/CLI's two methods will be fine.

Thanks

user2381422
  • 5,645
  • 14
  • 42
  • 56
  • Are you trying to call C++/CLI from C#, or C# from C++/CLI? I'm finding it difficult to understand where you're having trouble here. Perhaps a small code example is in order. – Jim Mischel Jul 24 '13 at 13:24
  • I am calling C++/CLI from C#. The problem is that C' supports default values for method parameters, and C++/CLI does not. So how do you deal with that? – user2381422 Jul 24 '13 at 13:29
  • 1
    It shouldn't matter when calling a method in C++/CLI from C#. – Tory Jul 24 '13 at 13:33
  • From C#, you should see 2 method overloads (`void MyMethod()` and `void MyMethod(string argument)`). – Cédric Bignon Jul 24 '13 at 13:40
  • @CédricBignon Yes that was exactly my question. Do I have to use two separate methods? – user2381422 Jul 24 '13 at 13:43
  • In C++/CLI yes. And in C#, it will appear as two method overloads. Why don't you try? – Cédric Bignon Jul 24 '13 at 13:45
  • Actually I can get away with one method both in C# and in C++/CLI. – user2381422 Jul 24 '13 at 13:58
  • @user2381422 Could you write exactly what your problem is? The signature of your method, in which language, how you want to call one method from the other language... – Cédric Bignon Jul 24 '13 at 14:00
  • I really don't see the problem. The C++/CLI code doesn't support default arguments, so you only have one method and you always have to pass it an argument. Or are you trying to duplicate a C# class's functionality in C++/CLI? – Jim Mischel Jul 24 '13 at 14:01

0 Answers0