   Array in managed C++ class?!?
  OK... I'm very annoyed. This whole thing is making me resist .NET even more.I'm trying to create an array as a member variable in one class of another class. When I try to compile, it bitches at me about mixed types and whatnot.Here's the code:#include "Space.h"ref class CBoard{public:CBoard(void);private:CSpace mSpaceArray[8];};Simply compiling this gives me:error C2728: 'CSpace' : a native array cannot contain this managed typeerror C3265: cannot declare a managed 'mSpaceArray' in an unmanaged 'CBoard'I have been looking all over and found various solutions. All these do is give me different errors. For example, I tried doing it as a pointer instead. Same deal. I've tried the bit where you do a "new" right there in the declaration. Same deal. I've even tried to rewrite this as simply an array of 'int' so as to remove the other (very skeleton) class out of the formula. Same thing.Certainly it can't be that difficult to have an array of one class contained as a member variable of another class. What gives?   
  did you try;System::Array<CSpace> mSpaceArray;and then gcnew'ing an instance of that?You might have to hold "CSpace*" instead of an instance.I'm confusd about your pointer example as I've been able to store pointers to non-managed types in a managed type just fine.If you haven't solved this by the time I get back here tomorrow I'll dig out my C++/cli book and see what gives; I'd do it now but I've just got in from a night out..   ;  OK... the difference was that my compiler options were set to /clr:pure rather than simply /clr. I changed that and used the line:static array<CSpace^> ^mSpaceArray = gcnew array<CSpace^>(8);That seems to have worked. (So far...)   ;Quote:Original post by InnocuousFoxOK... the difference was that my compiler options were set to /clr:pure rather than simply /clr. I changed that and used the line:static array<CSpace^> ^mSpaceArray = gcnew array<CSpace^>(8);That seems to have worked. (So far...)Erm, that doesn't do what you had above. That's a static member of the class, and so it will be a single static instance (accessible by all other instaces of the class);  Theoretically, there will only be one of these CBoard objects anyway. Be that as it may, when I remove the 'static', I get this:error C3845: 'CBoard::mSpaceArray': only static data members can be initialized inside a ref class or value typeI actually pulled the code that I used from the VS help file example. It has to do something with the memory management of arrays.   ;Quote:Original post by InnocuousFoxTheoretically, there will only be one of these CBoard objects anyway. Be that as it may, when I remove the 'static', I get this:error C3845: 'CBoard::mSpaceArray': only static data members can be initialized inside a ref class or value typeI actually pulled the code that I used from the VS help file example. It has to do something with the memory management of arrays.That's because you need to move the initialization to the constructor.Also, why are you using C++/CLI? For interop between an unmanaged and managed layer? If you're just using it as a first class .Net language, while possible, is not recommended.   ;  *shrug*I'm new to .NET. I'm a raw C++ guy. I'm just doing a few simple Windows Forms projects to show some quick stuff.I'll get there eventually... Thx.   ;Quote:Original post by InnocuousFox*shrug*I'm new to .NET. I'm a raw C++ guy. I'm just doing a few simple Windows Forms projects to show some quick stuff.I'll get there eventually... Thx.That's fine, but don't go around blaming the platform when you're deliberately using the most obtuse language that can target it.   ;  I wouldn't call any part of InnocuousFox's posts "blaming". He's merely expressing fustration, which could easily be directed inwards rather than outwards for all we know.He's not the only one who likes to let off a little steam about Microsoft's abomination that is C++/CLI.   ;  Having used it laterly I feel 'abomination' is the wrong term for C++/CLI. Sure, it's not the most friendly of languages but, aside from some brain bending when I needed to deal with some callback stuff going from a templated native class to a managed one, I haven't found it that bad for doing what it does, namely bridging the gap between the native and managed worlds.Being bolted onto C++ was never going to win it any beauty awards but, so far, what I've run into with the language makes sense.Heck, in this case it seems to be a case of not understanding the tool being used correctly rather than a problem with C++/CLI itself.Don't get me wrong, unless I decide I hate myself, C# is likely to be my first choice .Net language but I do feel C++/CLI its more bad press than it deserves at times.   