fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct Cell
  5. {
  6. Cell(int height) : _height(height) {}
  7. int height() const {return _height;}
  8.  
  9. private:
  10. int _height;
  11. };
  12.  
  13. int main()
  14. {
  15. std::vector<Cell> v = { 2, 4, 8, 16, 32 };
  16.  
  17. for (std::size_t index = 0; index < v.size(); ++index)
  18. std::cout << "Height at index " << index << " is " << v[index].height() << '\n';
  19. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Height at index 0 is 2
Height at index 1 is 4
Height at index 2 is 8
Height at index 3 is 16
Height at index 4 is 32