-1

Receiving two errors trying to compile my files. (Received a down vote without an explanation; I fail to see how this violates any SO guidelines.)

1) 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 I attempted to add the flags in Eclipse Mars, but it doesn't seem to have worked. Could that be the only thing i'm missing?

2) \DeckOfCards.h:21:8: error: 'array' in namespace 'std' does not name a template type This is in regards to the std::array<Card,52> cards_; line in my deck of cards header file. This is my first time attempting to build a deck of cards with multiple classes...or a single class for that matter so if i'm making an obvious error I apologize.

EDIT: Exact Message from the Compiler:

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)

If I recompile a second time after receiving these errors without changing anything I receive a ton more errors everywhere else across multiple files; is that normal?

Main

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

Card.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.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;
    }

}

Card.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;
        }
    }
}
StormsEdge
  • 854
  • 2
  • 10
  • 35
  • If you use C++11 features, like `std::array`, you have to tell the compiler that (unless you have g++ 6.1). Use option `-std=c++11`. And add it properly. .-) – Bo Persson Jul 12 '16 at 12:01
  • @BoPersson I thought I added it properly by putting the flags in. This might be a silly question, but is their an IDE that is good for beginners where these compiler options and such are included? – StormsEdge Jul 12 '16 at 12:04
  • @StormsEdge Well, it's my biased opinion, but I think that VisualStudio, Code::Lite or QtCreator are much more user friendly when it comes to C++. But getting back to the topic: you definitely must check if you have proper flags set. Could you post the line from the output where gcc is called? – Lehu Jul 12 '16 at 12:35
  • @Lehu I apologize, where would I find that? I am new to C++. I may switch to Visual Studio as i'm new and Eclipse may have been a little over my head to start. – StormsEdge Jul 12 '16 at 12:44
  • @StormsEdge Do not apologise for not knowing :) . I personally used Eclipse for as short time as it was possible ;), so I'm not sure, but there probably should be a card called Output or Build or Console. There you should see command which was issued by eclipse to compile your program. – Lehu Jul 12 '16 at 12:57
  • @Lehu =] See edits above! – StormsEdge Jul 12 '16 at 13:01
  • 1
    @StormsEdge And you have your answer: This is the command used to invoke compiler: `g++ -O0 -g3 -Wall -c -fmessage-length=0 -o TexasHoldemMain.o "..\\TexasHoldemMain.cpp"` The flag -std=c++11 is not there. To ba able to use std::array in your code and other new features you have to have this flag. – Lehu Jul 12 '16 at 13:04

1 Answers1

2

You have to set -std=c++11 flag for GNU compiler.

According to Eclipse forums:

  1. Right-click the project and go to "Properties"
  2. Go to: C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags.
  3. Put "-std=c++11" at the end.
Lehu
  • 761
  • 4
  • 14