Note that there are some explanatory texts on larger screens.

plurals
  1. POArray works while vector doesn't. What am i doing wrong?
    primarykey
    data
    text
    <p>I'm making a Tic-tac-toe game and i have a board class which contains 9 instances of tile class and does something with them. At first i used a C array to create those instances <code>Tile board[MAX_TILES]</code> and everything works fine with them. However i want to use vectors instead since they're safer so i tried the same with vectors <code>std::vector&lt;Tile&gt; board(MAX_TILES);</code> but instead i'm getting a bunch of errors in my .cpp file and 2 errors in my .h file.</p> <p>I'm not used to vectors yet since i've been taught to use C style arrays by our college professors. What am i doing wrong?</p> <p>Here is my Board.h and the errors, if you need the .cpp i'll provide:</p> <pre><code>#ifndef BOARD_H #define BOARD_H #include &lt;SFML\Window.hpp&gt; #include &lt;vector&gt; #include "tile.h" #define MAX_TILES 9 enum Position { TOP_LEFT = 0, TOP_MIDDLE = 1, TOP_RIGHT = 2, MIDDLE_LEFT = 3, MIDDLE_MIDDLE = 4, MIDDLE_RIGHT = 5, BOTTOM_LEFT = 6, BOTTOM_MIDDLE = 7, BOTTOM_RIGHT = 8 }; class Board { private: std::vector&lt;Tile&gt; board(MAX_TILES); //Tile board[MAX_TILES]; void positionTiles(); public: //Constructors Board(); Board( TileState tileState ); //Methods void clearBoard(); void drawBoard(sf::RenderWindow&amp; window); }; #endif </code></pre> <p>the errors 1 and 2 are from .h and others are from .cpp:</p> <pre><code>Error 1 error C2059: syntax error : 'constant' Error 2 error C2059: syntax error : 'constant' Error 3 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 4 error C2228: left of '.setTilePosition' must have class/struct/union Error 5 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 6 error C2228: left of '.setTilePosition' must have class/struct/union Error 7 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 8 error C2228: left of '.setTilePosition' must have class/struct/unio Error 9 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 10 error C2228: left of '.setTilePosition' must have class/struct/union Error 11 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 12 error C2228: left of '.setTilePosition' must have class/struct/union Error 13 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 14 error C2228: left of '.setTilePosition' must have class/struct/union Error 15 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 16 error C2228: left of '.setTilePosition' must have class/struct/union Error 17 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 18 error C2228: left of '.setTilePosition' must have class/struct/union Error 19 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 20 error C2228: left of '.setTilePosition' must have class/struct/union Error 21 error C3867: 'Board::board': function call missing argument list; use '&amp;Board::board' to create a pointer to member Error 22 error C2109: subscript requires array or pointer type 29 Error 23 error C2228: left of '.setTileState' must have class/struct/union Error 24 error C3867: 'Board::board': function call missing argument list; use '&amp;Board::board' to create a pointer to member Error 25 error C2109: subscript requires array or pointer type Error 26 error C2228: left of '.setTileState' must have class/struct/union Error 27 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 28 error C2228: left of '.getTileSprite' must have class/struct/union Error 29 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) 45 Error 30 error C2228: left of '.getTileSprite' must have class/struct/union Error 31 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 32 error C2228: left of '.getTileSprite' must have class/struct/union Error 33 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 34 error C2228: left of '.getTileSprite' must have class/struct/union Error 35 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 36 error C2228: left of '.getTileSprite' must have class/struct/union Error 37 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) 49 Error 38 error C2228: left of '.getTileSprite' must have class/struct/union Error 39 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 40 error C2228: left of '.getTileSprite' must have class/struct/union Error 41 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 42 error C2228: left of '.getTileSprite' must have class/struct/union Error 43 error C2677: binary '[' : no global operator found which takes type 'Position' (or there is no acceptable conversion) Error 44 error C2228: left of '.getTileSprite' must have class/struct/union </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload