[英]Acces an element in a vector of pointers
This is probably very simple but I can't find it: 这可能很简单,但我找不到它:
I want to acces an element in a vector of pointers 我想访问指针向量中的元素
class Tile
{
public:
Tile(int xPosition, int yPosition, float tileWeight);
float getValue() const {return value;};
void setValue(float newValue) {value = newValue;};
int getXPos() const {return xPos;};
int getYPos() const {return yPos;};
void setXPos(int newPos) {xPos = newPos;};
void setYPos(int newPos) {yPos = newPos;}
private:
int xPos;
int yPos;
float value;
};
class Enemy : public Tile
{
public:
Enemy(int xPosition, int yPosition, float strength);
};
In another class 在另一堂课
std::vector<Enemy*> enemies;
enemies = myWorld->getEnemies(5);
How can I acces the value of just the first member in another class I can't seem to acces it in another class 我如何才能在另一个班级中只访问第一个成员的值,我似乎无法在另一个班级中访问它的值
MySquare::movePlayer(std::vector <int> directions, std::vector<Enemy*> enemies,std::vector<int*> healthPks){
}
例如,要在向量的第一项上调用getValue
函数,请使用
enemies[0]->getValue();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.