Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vector of pairs with user-defined class objects

I'm trying to write a board game playing program (in C++). I have 2 classes called Move and Board. In my Board constructor, I am using a pair<char, Move>. It seems like it is not recognizing the class Move, even though I #include it in the header file. I get the error message: "missing ',' before identifier 'coord' " and " 'coord' : undeclared identifier". Here is my code:

Move.h:

#include <utility>
#include <vector>

using namespace std;

class Move{
    private:
        pair<int,int> coordinates;
    public:
        Move(int,int);
};

Move.cpp:

#include "Move.h"

Move::Move(int x, int y){
    coordinates.first = x;
    coordinates.second = y;
}

Board.h:

#include "Move.h"

class Board{
    private:
        vector<pair<char, Move> > board_state;
    public:
        Board(vector<pair<char, Move> >);
};

Board.cpp:

#include "Board.h"

Board::Board(vector<pair<char P, Move coord> > state){
     board_state = state;
}
like image 755
asrjarratt Avatar asked Feb 19 '26 03:02

asrjarratt


1 Answers

The template arguments for pair should be types only. So vector<pair<char P, Move coord>> should read vector<pair<char, Move>>.

like image 196
Jamerson Avatar answered Feb 21 '26 15:02

Jamerson