vector wont declare

So I have all of the include libraries but my vector wont declare two players. Can someone tell me how I am suppose to write this one line of code
1
2
3
4
5
6
7
8
9
10
class Eight
{
private:
    Card vector<int>playerone(7), vector<int>playertwo(7);
    int h;
    int stat(int h);
public:
    Eight();
    void execute();
};
Last edited on
You have two problems :
- Card vector<int>playerone(7) : what is card ?
- you're trying to initialize the vector values in their declarations. You can't do that (at least not like that). You have to initialize them in the contructor. For example :
1
2
3
4
5
6
7
8
9
10
class Eight
{
private:
    vector<int>playerone, playertwo;
    int h;
    int stat(int h);
public:
    Eight() : playerone(7), playertwo(7) {};
    void execute();
};
For another game I built I did it this way:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class Piece
{
private:
    int x, y, color;
public:
    Piece()
    {
        x = -1;
        y = -1;
        color = 2;
    }
    void setcolor(int c)
    {
        color = c;
    }
    void setposition(int x_pos, int y_pos, int c)
    {
        x = x_pos;
        y = y_pos;
        color = c;
    }
    void set(int x_pos, int y_pos)
    {
        x = x_pos;
        y = y_pos;
    }
    int getc()
    {
        return color;
    }
    int getx()
    {
        return x;
    }
    int gety()
    {
        return y;
    }
    void display();
};
class Board
{
private:
    Piece list[64], newlist[64];// you see how made an array of the pieces
    int x1, y1, h, loc, col;
    int status, redpiece, greenpiece, winner;
    int stat(int h);
    int inRange(int x, int y);
    int pieceAtLoc(int x, int y);
    int validPlacement(int x, int y, int loc, int col);
    void flip(int x, int y, int loc);
    void display();
    void move();
public:
    Board();
    void execute();
};

I am trying to do that with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Card
{
private:
    int number;
    char suit;
public:
    Card()
    {
        number = -1;
        suit = 'A';//clubs, spades, hearts, and diamonds
    }
    int gets()
    {
        return suit;
    }
    int getn()
    {
        return number;
    }
    void display();
};
class Eight
{
private:
    Card vector<int>one, two;
    int number, h;
    char type;
    int stat(int h);
public:
    vector<int>d;
    Eight();
    void execute(vector<int>d);
};
closed account (j3Rz8vqX)
Vector and arrays have different declaration designs:
 
Piece list[64], newlist[64];

Versus
 
vector<int> one, two;


The two above codes are appropriate.

The below code isn't:
 
Card vector<int>playerone(7), vector<int>playertwo(7);


Edit:
If you want a vector of objects, you would do something like this:
 
vector<Card> one, two;

It isn't the norm to put object names in front of vector, unless you're targeting a specific scope; usually applies with namespace and possibly public class vectors.
Last edited on
THANK YOU!...Did not know that i just placed the Card inside the brackets.
Topic archived. No new replies allowed.