1

I'm getting an error 'Expected class name' from my child class header file. After searching through stackoverflow, I tried to declare the base class in the child class header file and it works. However, I want to have it in a separate file...

child class [RefCard.h]

#ifndef RefCard_h
#define RefCard_h

#include <stdio.h>
#include "Cards.h"


class RefCard : public Cards
{
public:
    RefCard();
};
#endif /* RefCard_h */

I get the error message for the line 'class RefCard : public Card' If I add the line class Cards{};
right before class RefCard:public Cards
it works, but that's not what I want to do.

Class Cards is properly defined in Cards.h and implemented in Cards.cpp I guess there is an issue in the linking?

Cards.h

#ifndef Cards_h
#define Cards_h

#include <string>
#include "RefCard.h"
#include "RoleCard.h"
#include "PlayerCard.h"

class Cards{
private:
    std::string card_name;
    std::string card_textf;
    std::string card_textb;
public:
    Cards();
};

#endif /* Cards_h */

Cards.cpp

#include <stdio.h>
#include <iostream>
#include "Cards.h"

Cards::Cards(){
    card_name="";
    card_textf="";
    card_textb="";
}
mnova
  • 11
  • 2
  • 1
    Please post the contents of Cards.h. – R Sahu Feb 21 '17 at 04:44
  • @R Sahu I removed some code (accessors, mutators and other functions) to display it clearer here, but I still get the error message... – mnova Feb 21 '17 at 04:55
  • 1
    Most likely your issue is - circular includes. Why does the base class need to know anything about child classes? – Algirdas Preidžius Feb 21 '17 at 04:57
  • Thanks a lot! Is there any way (any tool) that you can use to track includes? – mnova Feb 21 '17 at 05:00
  • You have the line `#include "RefCard.h"` in Card.h. You don't need it. Remove it. I am guessing `RoleCard` and `PlayerCard` are derived from `Card` too. In that case remove the lines `#include "RoleCard.h"` and `#include "PlayerCard.h"` from Card.h. – R Sahu Feb 21 '17 at 05:01

0 Answers0