1

这可能很简单,但我找不到:

我想访问指针向量中的元素

 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){

}
4

1 回答 1

2

例如,要getValue对向量中的第一项调用函数,请使用

enemies[0]->getValue();
于 2013-01-06T20:05:51.077 回答