views:

240

answers:

1

Try as I might, I cannot convert this Managed C++ code to C++/CLI. Can someone give a pointer (pun intended)?

static String *ignoreStrings[];

Later in the code, an Add(string) method is called on it. Elsewhere, in some C# code,

new String[]{"foo", "bar"}

is passed into a function that is somehow cast into the type of ignoreStrings above.

I've tried this syntax:

static array<String^> ^ignoreStrings;

But it can't cast from that C# array, and it doesn't have an add method either.


Edit: More complete code in the hopes that this changes the question somehow...

private:
 static String *ignoreStrings[];

public:
 void AddIgnoreString(String *ignore)
 {
  AddOneIgnoreString(ignore);
 }

 void SetIgnoreStringData(String *ignore[])
 {
  SetIgnoreStrings(ignore);
 }

 static void SetIgnoreStrings(String *ignore[])
 {
            ignoreStrings = ignore;
 }
 static void AddOneIgnoreString(String ^ignore)
 {
  ignoreStrings->Add(ignore);
 }

Elsewhere, from C# code, this call is made:

SetIgnoreStrings(new String[]{"foo", "bar"});

This is what I tried to convert the C++ code to:

private:
 static array<String^> ^ignoreStrings;

public:
 virtual void AddIgnoreString(String ^ignore)
 {
  AddOneIgnoreString(ignore);
 }

 virtual void SetIgnoreStringData(array<String^> ^ignore)
 {
  SetIgnoreStrings(ignore);
 }

 static void SetIgnoreStrings(array<String^> ^ignore)
 {
  ignoreStrings = ignore;
 }

 static void AddOneIgnoreString(String ^ignore)
 {
  ignoreStrings->Add(ignore);
 }

 static array<String^> ^GetIgnoreStrings()
 {
  return ignoreStrings;
 }
+2  A: 

Your try

static array<String^> ^ignoreStrings;

should work!

.NET arrays do not have an Add method (not in C++/CLI or C#!). If you mean a List (which has an Add() method) then it would be

static System::Collections::Generic::List<String ^> ^ignoreStrings;
rstevens
I'm going to edit the question with more complete code.
yodaj007