Ah. Thanks for all the help!
@Athar:
I was wondering if I could access the vectors like they were arrays...now I know that's true.
1 2 3
|
towers.at(4).someFunction();
//or just:
towers[4].someFunction();
|
This is exactly what I needed to know to access the members. Thanks!
@Kyon
I'm not completely understanding the concept of using a Tower* vector...From what I can gather, would that just point at the address of the original Tower class, or one of its implements? If that is what its doing (unless I am completely missing the point), that's not exactly what I was aiming for...
@bolohardik
(if Tower instances are non-copyable)
Do you mean Tower class has private members? or something else? |
I have this same question myself. To avoid further confusion to anyone, I will gladly share what my Tower class is as of right now:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
class Tower {
public:
const char * name; //name of the tower
char symbol; //the tower's icon
const char * color; //the tower's color
int x_pos; //x position tower is placed at
int y_pos; //y position tower is placed at
int range; //region attacks can reach to
int power; //the attack strength
int speed; //how fast it attacks
int price[3]; //the cost to buy it
int upgrade[3]; //the cost to upgrade it
int upgrade2[3]; //the cost to upgrade it
int upgrade3[3]; //the cost to upgrade it
int upgrade4[3]; //the cost to upgrade it
//(different for difficulty)
int refund; //money returned to remove tower
//(75% of tower and upgrade costs)
int shots; //the amount of shots taken
int kills; //the amount of kills acquired
} ;
//for simplicity:
Tower tower;
|
As you can see, none of my members are private, nor do I have any functions (at least, not yet...I am unsure if I will need them or not yet).
That either doesn't work at all (if Tower instances are non-copyable) or is slow (unless it has a simple structure). |
If I am understanding what "non-copyable" and "simple structure" correctly, then my class should be copyable, and it seems to be 'simple structured'. Or am I missing some information about copyable and non-copyable classes?
A new question has arose. When I am using
towers.push_back(tower);
to add a new element of Tower, does it copy the original, unchanged class, with nothing defined? If this is true, then I suppose I would have to create a function to set the default values after it is added to the vector.
Thanks again, this is really helping!