J
JoeC
I am writing a program and I would like to pass an array of objects to
a function and from that object I want to return a valuse to that
function how do I do it?
Here is what I have:
terrain * t; <- an array of different kinds of terrain.
This is the line of code:
int mod = t[b->(GetSpace(lp2,lp1)]->getDef();
Here is the constructor:
mapmgt::mapmgt(board * bo, terrain * te, int x, int y){
b = bo; //board object
t = te; //terrain object
xlen = x; //size of the array
ylen = y;
if(xlen > 99 || ylen > 99){ // map can only be 100 x 100.
MessageBox(NULL, "The map is too big, edit the program!", "Error!",
MB_OK);
}
}
Here is the array:
static terrain trn[5]; //terrain array
Terraine object:
class terrain : public graphic, public color{ //inclueds my graphic lib
int mvcost; //movemtn cost to move throw that space
int defence; //defensive adjustment when implemented
public:
terrain();
terrain(int, int, int);
void SetColor(int rn, int bn, int gn){r = rn; b = bn; g = gn;}
void SetAll(int, int, int, BYTE c[]); //sets the color and graphic
void SetData(int, int); //sets defensive bonus and movment cost
int move()const {return mvcost;} //return the movemnt cost
int getDef()const {return defence;} <-the runcion I want to access.
};
To recap, I want to send the terrain array and the map object to the
map manager object and in that object have them as data types of the
object then when I need then I can access the data from the terrain
type based on a space of the map. Each terrain type is an int which
coresponds to the array element which has the data for that terrain
type.
ex 0 = open, 1 = water 2 = trees and on.
a function and from that object I want to return a valuse to that
function how do I do it?
Here is what I have:
terrain * t; <- an array of different kinds of terrain.
This is the line of code:
int mod = t[b->(GetSpace(lp2,lp1)]->getDef();
Here is the constructor:
mapmgt::mapmgt(board * bo, terrain * te, int x, int y){
b = bo; //board object
t = te; //terrain object
xlen = x; //size of the array
ylen = y;
if(xlen > 99 || ylen > 99){ // map can only be 100 x 100.
MessageBox(NULL, "The map is too big, edit the program!", "Error!",
MB_OK);
}
}
Here is the array:
static terrain trn[5]; //terrain array
Terraine object:
class terrain : public graphic, public color{ //inclueds my graphic lib
int mvcost; //movemtn cost to move throw that space
int defence; //defensive adjustment when implemented
public:
terrain();
terrain(int, int, int);
void SetColor(int rn, int bn, int gn){r = rn; b = bn; g = gn;}
void SetAll(int, int, int, BYTE c[]); //sets the color and graphic
void SetData(int, int); //sets defensive bonus and movment cost
int move()const {return mvcost;} //return the movemnt cost
int getDef()const {return defence;} <-the runcion I want to access.
};
To recap, I want to send the terrain array and the map object to the
map manager object and in that object have them as data types of the
object then when I need then I can access the data from the terrain
type based on a space of the map. Each terrain type is an int which
coresponds to the array element which has the data for that terrain
type.
ex 0 = open, 1 = water 2 = trees and on.