나는 Tic-tac-toe 게임을 만들고 있는데, 나는 타일 클래스의 9 가지 인스턴스를 포함하고있는 보드 클래스를 가지고 있으며, 그들과 함께 뭔가를한다. 처음에는 C 배열을 사용하여 해당 인스턴스 인 Tile board[MAX_TILES]
을 만들었고 모든 것이 제대로 작동합니다. 그러나 나는 벡터 대신 std::vector<Tile> board(MAX_TILES);
벡터와 동일한 시도했지만 그 대신에 내 .cpp 파일 및 내 .h 파일에서 2 오류에서 오류 무리를 가져오고 있기 때문에 대신 벡터를 사용하고 싶습니다.벡터가없는 동안 배열이 작동합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
저는 우리 대학 교수가 C 스타일 배열을 사용하도록 가르쳐 왔기 때문에 아직 사용하지 않았습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
#ifndef BOARD_H
#define BOARD_H
#include <SFML\Window.hpp>
#include <vector>
#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<Tile> board(MAX_TILES);
//Tile board[MAX_TILES];
void positionTiles();
public:
//Constructors
Board();
Board(TileState tileState);
//Methods
void clearBoard();
void drawBoard(sf::RenderWindow& window);
};
#endif
오류 (1)과 (2) .H에서하고 다른 .CPP에서 다음과 같습니다 :
가 여기 내 Board.h 및 오류 당신이 .CPP 필요하면, 내가 제공하는 것이다
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 '&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 '&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
.cpp도 표시 하시겠습니까? – Vikdor