构建卡片组的多个错误

时间:2016-07-12 11:55:40

标签: c++ c++11 eclipse-mars playing-cards

尝试编译我的文件时收到两个错误。 (在没有解释的情况下收到了投票;我没有看到这违反了任何SO准则。)

1) std::array<Card,52> cards_; 我试图在Eclipse Mars中添加标记,但它似乎没有效果。这可能是我唯一缺少的吗?

2) 07:56:55 **** Incremental Build of configuration Debug for project TexasHoldem **** Info: Internal Builder is used for build g++ -O0 -g3 -Wall -c -fmessage-length=0 -o TexasHoldemMain.o "..\\TexasHoldemMain.cpp" In file included from c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\array:35:0, from ..\DeckOfCards.h:11, from ..\TexasHoldemMain.cpp:5: c:\mingw\lib\gcc\mingw32\4.9.3\include\c++\bits\c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ In file included from ..\TexasHoldemMain.cpp:5:0: ..\DeckOfCards.h:21:8: error: 'array' in namespace 'std' does not name a template type std::array<Card,52> cards_; ^ 07:56:56 Build Finished (took 233ms) 这与我的卡牌头文件中的//Texas Holdem implementation #include <iostream> #include "Card.h" #include "DeckOfCards.h" int main() { DeckOfCards deck; deck.printDeck(); return(0); } 行有关。这是我第一次尝试用多个班级来构建一副卡片......或者是一个单独的班级,所以如果我犯了一个明显的错误我会道歉。

编辑:编译器的确切消息:

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

#ifndef DECKOFCARDS_H_
#define DECKOFCARDS_H_

#include <array>

class DeckOfCards
{

    public:
        DeckOfCards();
        void printDeck();

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


};

#endif /* DECKOFCARDS_H_ */

如果我在收到这些错误后第二次重新编译而没有改变任何内容,我会在多个文件的其他地方收到更多错误;那是正常的吗?

主要

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

#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();
};

DeckOfCards.h

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


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

void DeckOfCards::printDeck()
{

    bool first = true;

    for(auto card : cards_)
    {
        if(!first)
        {

            std::cout << ", ";

        }
        card.printCard();
        first = false;
    }

}

Card.h

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

Card::Card()
{}

void Card::printCard()
{

    switch(suit)
    {

    case Hearts:
        std::cout << "♥";
        break;
    case Diamonds:
        std::cout << "♦";
        break;
    case Clubs:
        std::cout << "♣";
        break;
    case Spades:
        std::cout << "♠";
        break;
    }
    if(value < Jack)
    {

        std::cout << (int)value;
    }
    else
    {
        switch(value)
        {

        case Jack:
            std::cout << 'J';
            break;
        case Queen:
            std::cout << 'Q';
            break;
        case King:
            std::cout << 'K';
            break;
        case Ace:
            std::cout << 'A';
            break;
        }
    }
}

DeckOfCards.cpp

{{1}}

Card.cpp

{{1}}

1 个答案:

答案 0 :(得分:2)

你必须为GNU编译器设置-std = c ++ 11标志。

根据Eclipse论坛:

  1. 右键单击项目,然后转到&#34;属性&#34;
  2. 转到: C / C ++ Build - &gt;设置 - &gt;工具设置 - &gt; GCC C ++编译器 - &gt; 其他 - &gt;其他旗帜。
  3. Put&#34; -std = c ++ 11&#34;最后。