From: dmt AT bigfoot DOT com (Jeff W./DMT) Newsgroups: comp.os.msdos.djgpp Subject: Re: PLEASE help with vectors! Date: Wed, 22 Apr 1998 22:29:38 GMT Organization: ZipLink -- America's Hottest ISP Lines: 104 Message-ID: <353e6e9e.405303@news.ziplink.net> References: <353d29bc DOT 235411 AT news DOT ziplink DOT net> <353D613B DOT D502B628 AT home DOT com> NNTP-Posting-Host: chi-ip-1-65.ziplink.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk well, I got a great suggestion which is to implement a vector class as follows (assuming your data is of integer type): typedef struct BaseType { //base layer of tiles int tileno; //which tile number to load from the datafile int opaque; //can you see past the tile? For line of sight algorithm int collision; //for collision detection, see #defines int flag; //misc flag }; class vector { public: vector (void) { width = 20; //arbitrary starting map size of 20x15 height = 15; data = new int[width * height]; } ~vector (void) { delete[] data; } int resize (const int _width, const int _height) { if ((_width <= 0) || (_height <= 0)) return -1; width = _width; height = _height; delete[] data; data = new int[width * height]; return 0; } int* operator[] (const int _y) { /* FIXME: test for index out of range. */ return &data[_y * width]; } private: int width; int height; int* data; }; however, my data type is not an INT, it's a struct containing 4 structs as follows: typedef struct FringeType //non-pickupable objects { int tileno; int flag; }; typedef struct ObjType //normal objects { int tileno; int active; //shouldit be blitted??? int flag; }; typedef struct RoofType //for the roof of buildings/etc { int tileno; int flag; }; typedef struct MapStruct //just contains all the other structures into 1 { BaseType base; FringeType fringe; ObjType obj; RoofType roof; }; NOTE: MapStruct is the main structure, i.e. instead of having DATA as type int, it should be type MapStruct. Sooooo, the problem becomes this: When you use the [] operator, how can I make it so that I know what field to access?? I.e. what I would ideally like to be able to do is to say: AMap[40][2].base.tileno = 5; or something similar. --Jeff W. "The finding of DMT in normal human body fluids opens up interesting moral and legal questions. Since DMT is illegal, as is 'any substance, compound or mixture' containing DMT, it would seem that we are all guilty of possesion of a controlled substance" -Jonathon Ott My weird, trippy page: http://www.geocities.com/SunsetStrip/Alley/3450/index.html