0

There are three .h files

A.h:

#ifndef __A_H__
#define __A_H__

#include"Card.h"
#include"B.h"

struct A{
    Card card;
    .....
};

void getCards(A *a, int num);

#endif

B.h

#ifndef __B_H__
#define __B_H__

#include"Card.h"
#include"A.h"

struct B{
    Card card;
    .....
};

void getCards(A *a, B *b, int num);

#endif

Card.h

#ifndef __CARD_H__
#define __CARD_H__

struct Card{
    int num;
    char *type;
};

#endif

Since A.h and B.h includes each other, not all header files are included.

Please give me some advices.

soonoo
  • 867
  • 1
  • 10
  • 35

1 Answers1

2

As far as I can see, you don't need to include "B.h" in your "A.h" file. So remove it to reduce dependencies. Including "A.h" in your "B.h" file also seems unnecessary. A simple forward declaration should be sufficient.

B.h

#ifndef __B_H__
#define __B_H__

#include"Card.h"

class A; // then you will have to include A.h in your B.cpp file

struct B{
    Card card;
    .....
};

void getCards(A *a, B *b, int num);

#endif
Mr.Yellow
  • 197
  • 1
  • 8