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 に答える