I've been googling and reading about this and didn't come up with an answer yet, maybe someone can help me with this.
I want my UserPile class to be able to access data members and class member functions from my CardPile class. I keep getting the error mention in the title. Could someone explain what is happening? The inheritance tutorials I have seen look just like my code except mine is m开发者_StackOverflow社区ultiple source code files.
//CardPile.h
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Card;
class CardPile
{
protected:
vector<Card> thePile;
//Card thePile[];
int pileSize;
public:
CardPile();
void insertCard( Card );
Card accessCard( int);
void displayPile();
void shuffle(); //shuffle the pile
void initializeDeck(); //create deck of cards
void deal(CardPile &, CardPile &);
void showHand();
bool checkForAce();
void discard(CardPile);
void drawCard(CardPile &);
};
//UserPlayer.h
using namespace std;
class UserPlayer: public CardPile
{
private:
//CardPile userPile;
public:
UserPlayer();
};
//UserPlayer.cpp
#include "UserPlayer.h"
#include "CardPile.h"
UserPlayer::UserPlayer()
{
}
I don't have anything happening in this UserPlayer class yet, because I will be using functions from the base class, so I want to at least see it compile before I start writing it.
Thanks for anyone's help.
You have to include CardPile.h
in UserPlayer.h
if you want to use the class CardPile
there.
You are also missing include guards in the headers, e.g.:
// CardPile.h:
#ifndef CARDPILE_H
#define CARDPILE_H
class CardPile {
// ...
};
#endif
Without this you are effectively including CardPile.h
twice in UserPlayer.cpp
- once from UserPlayer.h
and once via the line #include "CardPile.h"
UserPlayer.h needs to #include CardPile.h -- is that the case with your code?
精彩评论