为卡片组初始化std :: array <card,52>时出错

时间:2016-07-08 12:57:01

标签: c++ oop object playing-cards

我正在建立一个德州扑克游戏作为帮助学习OOP的项目。我用一个类多次构建了tictactoe,并决定继续使用类/结构相互交互的更具挑战性的东西。我试图在我的构造函数中从我的DeckOfCards类初始化我的牌组,我收到语法错误。不知道我做错了什么。有什么想法吗?

DeckOfCards::DeckOfCards() :初始化

中发生错误

收到每个钻石上的错误,表示符号“钻石”的值无法解析,符号“两个”无法解析..等等。等等

DeckOfCards.cpp

#include <iostream>
#include "DeckOfCards.h"
#include "Card.h"
#include <array>


DeckOfCards::DeckOfCards()
:
    cards_(
        {Diamonds, Two},
        {Diamonds, Three},
        {Diamonds, Four},
        {Diamonds, Five},
        {Diamonds, Six},
        {Diamonds, Seven},
        {Diamonds, Eight},
        {Diamonds, Nine},
        {Diamonds, Ten},
        {Diamonds, Jack},
        {Diamonds, Queen},
        {Diamonds, King},
        {Diamonds, Ace})
{

}

DeckOfCards.h

* DeckOfCards.h
 *
 * 
 *      
 */

#ifndef DECKOFCARDS_H_
#define DECKOFCARDS_H_

#include <array>

class DeckOfCards
{

    public:
        DeckOfCards();

    private:
        std::array<Card,52> cards_;


};

#endif /* DECKOFCARDS_H_ */

Card.h

* Cards.h
 *
 *  Created on: Jul 8, 2016
 *      Author: TAmend
 */

#ifndef CARD_H_
#define CARD_H_

struct Card
{

    enum Suit_Type
    {
        Diamonds,
        Hearts,
        Spades,
        Clubs,
    } suit;

    enum Value_Type
    {

        Two = 2,
        Three = 3,
        Four = 4,
        Five = 5,
        Six = 6,
        Seven = 7,
        Eight = 8,
        Nine = 9,
        Ten = 10,
        Jack = 11,
        Queen = 12,
        King = 13,
        Ace = 14
    } value;

    void printCard();
};



#endif /* CARD_H_ */

1 个答案:

答案 0 :(得分:1)

Suit_TypeValue_TypeCard的成员。您需要对其值进行限定:

DeckOfCards::DeckOfCards()
:
    cards_(
        {Card::Diamonds, Card::Two},
        {Card::Diamonds, Card::Three},
        {Card::Diamonds, Card::Four},
        {Card::Diamonds, Card::Five},

或将枚举移至全局范围。