构建一副纸牌的多个错误



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

1)c:mingwlibgccmingw324.9.3includec++bitsc++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试图在Eclipse Mars中添加标志,但它似乎没有奏效。 难道这就是我唯一缺少的东西吗?

2) DeckOfCards.h:21:8: error: 'array' in namespace 'std' does not name a template type 这是关于我的一副牌头文件中的std::array<Card,52> cards_;行。 这是我第一次尝试构建一副具有多个类别的纸牌......或者一个单一的类,所以如果我犯了一个明显的错误,我道歉。

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

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:mingwlibgccmingw324.9.3includec++array:35:0,
                 from ..DeckOfCards.h:11,
                 from ..TexasHoldemMain.cpp:5:
c:mingwlibgccmingw324.9.3includec++bitsc++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

 * 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_ */

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

纸牌组.cpp

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

卡.cpp

#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;
        }
    }
}
你必须

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

根据Eclipse论坛:

  1. 右键单击项目并转到"属性"
  2. 转到:C/C++ 构建 ->设置 -> 工具设置 -> GCC C++编译器 ->杂项 ->其他标志。
  3. 把"-std=c++11"放在最后。

相关内容

  • 没有找到相关文章

最新更新