xconspirisist |
11-04-2003 05:49 PM |
binding an integer to variables...
read this will proberbly help : http://www.linuxquestions.org/questi...hreadid=111948
hey, again, if you saw my last post about variables, you're proberbly wondering if this particular n00b is trying to do something rather odd with these variables, but there is some good coming of this. Really. :)
I have a function which is being send an integer, from another fuction.
I have 16 different variables. Variable01, Variable02, Variable03, etc.
I have some class thing .. ( ?! ) which uses these variables. I would like to do a function that does the thing with the classes, Variable01.addfruit -- depending on what integer is send the the function will depend on what variable the class uses.
Now your really confused. Hers's code.
location.cpp
Code:
using namespace std;
// Class for the new_location arithlogram
enum { none = 0, north = 1,east = 2,south = 4,west = 8 };
class square {
private:
int contents;
public:
bool can_go(int direction) { return (contents & direction) ? true : false; }
square(void) { contents = none; }
square(int which) {
contents = none;
addDirection(which);
}
void addDirection(int direction) {
if(!can_go(direction)) (contents |= direction);
else cout << "You cannot have more than one of the same thing you greedy bastard.\n";
}
//
//
// void removeDirection(int direction) {
// if(is_inside(direction)) (contents ^= direction);
// else cout << "You cannot remove something you do not have ..." << endl;
}
//
//
// void emptyDirections(void) { contents = none; }
//
// void printDirections(void) {
// cout << "This basket has "
// << (is_inside(north)) << " north, "
// << (is_inside(east)) << " east, "
// << (is_inside(south)) << " south, "
// << (is_inside(west)) << " west.\n";
// }
//
// ~square(void) { /*...*/ }
};
square sq1;
square sq2;
square sq3;
square sq4;
square sq5;
square sq6;
square sq7;
square sq8;
square sq9;
square sq10;
square sq11;
square sq12;
square sq13;
square sq14;
square sq15;
square sq16;
void load_location( void ) {
cout<< "Game : locations system loaded\r\n";
// sq1.addDirection(north);
sq1.addDirection(east);
sq1.addDirection(south);
// sq1.addDirection(west);
sq2.addDirection(north);
sq2.addDirection(east);
sq2.addDirection(south);
// sq2.addDirection(west);
sq3.addDirection(north);
sq3.addDirection(east);
sq3.addDirection(south);
// sq3.addDirection(west);
sq4.addDirection(north);
sq4.addDirection(east);
// sq4.addDirection(south);
// sq4.addDirection(west);
// sq5.addDirection(north);
sq5.addDirection(east);
sq5.addDirection(south);
sq5.addDirection(west);
sq6.addDirection(north);
sq6.addDirection(east);
sq6.addDirection(south);
sq6.addDirection(west);
sq7.addDirection(north);
sq7.addDirection(east);
sq7.addDirection(south);
sq7.addDirection(west);
sq8.addDirection(north);
sq8.addDirection(east);
// sq8.addDirection(south);
sq8.addDirection(west);
// sq9.addDirection(north);
sq9.addDirection(east);
sq9.addDirection(south);
sq9.addDirection(west);
sq10.addDirection(north);
sq10.addDirection(east);
sq10.addDirection(south);
sq10.addDirection(west);
sq11.addDirection(north);
sq11.addDirection(east);
sq11.addDirection(south);
sq11.addDirection(west);
sq12.addDirection(north);
sq12.addDirection(east);
// sq12.addDirection(south);
sq12.addDirection(west);
// sq13.addDirection(north);
// sq13.addDirection(east);
sq13.addDirection(south);
sq13.addDirection(west);
sq14.addDirection(north);
// sq14.addDirection(east);
sq14.addDirection(south);
sq14.addDirection(west);
sq15.addDirection(north);
// sq15.addDirection(east);
sq15.addDirection(south);
sq15.addDirection(west);
sq16.addDirection(north);
// sq16.addDirection(east);
// sq16.addDirection(south);
sq16.addDirection(west);
}
void new_location( characterData * ch, int location, int direction ) {
switch ( direction ) {
case 1: // North
if (sq1.can_go (north)) {
// update to north
}
break;
case 2: // East
break;
case 4: // South
break;
case 8: // West
break;
}
}
okey, the new_location function. see its getting the location integer ? well, I want the sq# ( sq1. in the example ) to refur to whatever the integer is the fucntion is being sent.
How do I do that ?
|