I am receiving the error too many initializers
in my deckofcardsclass.cpp
class file. I've seen several posts about this, but they don't directly relate and what i'm running into is a bit more complicated since I am populating the array with instances of another class. Is it merely a syntax error? Or is my logic behind the initialization incorrect?
To Be Clear: The error is occurring in the implementation file when initializing the cards_ array
Class Header
#pragma once
#ifndef DECKOFCARDS_H_
#define DECKOFCARDS_H_
#include <array>
#include "Card.h"
class DeckOfCards
{
public:
DeckOfCards();
void printDeck();
private:
std::array<Card, 52> cards_;
};
#endif // !1
Class Implementation
#include "stdafx.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 header
#pragma once
#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
_