passing a __nogc array in a method...

Well my code is slpitted in: one myClasses.h and one myClasses.cpp files and it's something like this:

// *** myClasses.h: ***
#define SIZE 10
public __gc class MyClass;
public __gc class AnotherMyClass;

public __gc class MyClass{
public:
  MyClass();
  void myMethod();
private:
  bool myArray __nogc[SIZE];
  AnotherMyClass* anotherMyClass;
};

public __gc class AnotherMyClass{
public:
AnotherMyClass(bool myArray __nogc[SIZE]){ // constructor is inlined
  for(int i=0; i<SIZE; i++)
    this->myArray\[i\] = myArray\[i\];
}
private:
  bool myArray __nogc\[SIZE\];
};

//*** myClasses.cpp: ***
MyClass::MyClass(){
  for(int i; i<SIZE; i++)
     myArray\[i\]=true;
anotherMyClass = NULL;
}

void MyClass::myMethod(){
anotherMyClass = new AnotherMyClass(myArray);
}

// *** Oh, and this is the main (in another file): ***
int _tmain(){
MyClass* myClass = new MyClass();
myClass->myMethod();
return 0;
}

So far I receive this error, but I can't understand why and how to fix it (without using managed arrays):
error C2664: 'AnotherMyClass::AnotherMyClass' : cannot convert parameter 1 from 'bool \[10\]' to 'bool \[\]'

I can't find anything on google too, help help!



Answer this question

passing a __nogc array in a method...

  • Jason Gerard

    Hi: I suspect that the reason this is failing is because MyClass::myArray is a member of a managed class and thus it decays not to a bool* but to bool* __gc - what is known as an interior pointer.

    In case of the  declaration of MyAnotherClass(bool myArray __nogc[SIZE]) this decays along the usual C and C++ path to bool*. Now we have the problem there is not implicit conversion form bool* to bool* __gc and hence you get the (rather confusing) error message you have reported.

    I have managed to get this to compile a couple of ways. There first way is to change the declaration of:

    MyAnotherClass(bool myArray __nogc[SIZE])

    to:

    MyAnotherClass(bool* __gc)

    The problem here is that you loose the size of the array.

    Another fix is to pass the array be reference: i.e. change the declaration to:

    MyAnotherClass(bool (&myArray) __nogc[SIZE])

    Hope this helps



  • passing a __nogc array in a method...