/***************************************************************************** *** FILE: array.cpp *** DATE: 04/10/2004 *** AUTHOR: Daniel Dementiev *** GOAL: This short example illustrates how to create managed array is MS *** Visual C++ managed extension. Please note how we use properties *** and methods inherited from Array class. *** To compile the project, use *** ...> cl array.cpp /clr *****************************************************************************/ #using using namespace System; __gc class Robot { private: static int curID = 1; int ID; int HP; // servce data members static Random *rnd = new Random; int rand(int max) { return rnd->Next(max)+1; }; public: Robot() : ID(curID++), HP(rand(100)) { Console::WriteLine(S"Robot {0} created", ID.ToString()); }; ~Robot() { Console::WriteLine(S"Robot {0} destroyed", ID.ToString()); } void PrintInfo() { Console::WriteLine(S"Robot {0} has {1} HP", ID.ToString(), HP.ToString() ); }; int getHP() { return HP; }; }; void main() { int N = 10, i; Robot* robots[] = __gc new Robot*[N]; for(i=0;iLength.ToString()); Console::WriteLine(S"IsFixedSize = {0}", robots->IsFixedSize.ToString()); Console::WriteLine(S"Rank = {0}", robots->Rank.ToString()); for(i=0;iRank;i++) Console::WriteLine(S"Dimension #{0}: lower bound:{1} upper bound: {2}", i.ToString(), robots->GetLowerBound(i).ToString(), robots->GetUpperBound(i).ToString() ); Console::WriteLine(S"'robots' type:"); Type *t = robots->GetType(); while( t ){ Console::WriteLine(S" {0}", t->ToString()); t = t->BaseType; } Console::WriteLine(S"-----------------------------"); }