1

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

1 Answer 1

2

For example to call getValue function on the first item in the vector, use

enemies[0]->getValue(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.