[英]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);
};
在另一堂課
std::vector<Enemy*> enemies;
enemies = myWorld->getEnemies(5);
我如何才能在另一個班級中只訪問第一個成員的值,我似乎無法在另一個班級中訪問它的值
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.