Inheritance error: "expected class name before" {'token "

I am writing a poker program where I have a Deck class class and a Hand class. The Hand class inherits from the Deck class, so it can use its printGroup method. However, when compiling, I get an error message:

expected class-name before '{' token

referring to the line:

 class Hand : public Deck{  

Here is the code for the two class headers. Can someone help me solve this problem?

// Header Title

#ifndef HAND_H
#define HAND_H

#include <iostream>
#include <vector>
#include "Deck.h"
#include "Card.h"

class Card;

class Hand : public Deck{    //error occurs from this line
public:
    Hand(){}
    void createHand(std::vector<Card> &, std::vector<Card> &);
};


#endif /* HAND_H */

// deck header

#ifndef DECK_H
#define DECK_H

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

class Card;

class Deck{
public:
    Deck(){}
    void createDeck(std::vector<Card> &);
    void printGroup(std::vector<Card> &, int);
    void sortDeck(std::vector<Card> &, int, int);
};

#endif /* DECK_H */
+3
source share
1 answer

, @marcog, , , (, Card.h Hand.h, Hand.h, Deck), .

, Card ( "class Card;" ). #include "Card.h"? , Card - , .

#include.h .h ++, . (, , , ), .cpp .

+3

Source: https://habr.com/ru/post/1778648/


All Articles