Inheritance error

hi ive been trying to do some inheritance in 2008 express edition and this is the error i get.

1>f:\c++ test\classbeech\classbeech\baseball.h(5) : fatal error C1014: too many include files : depth = 1024

could somebody help please

these are my files


Person.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>

#include <string> 
#include "Baseball.h"
using namespace std;



class Person  

 {  
	 
 public:  

     string m_strName;  

     int m_nAge;  

     bool m_bIsMale;  

    

     string GetName() 
	 { 
		 return m_strName; 
	 }  

    int GetAge() 
	{ 
		return m_nAge; 
	}  

     bool IsMale() 
	 { 
		 return m_bIsMale; 
	 }  

    

	Person(string strName = "", int nAge = 0, bool bIsMale = false): m_strName(strName), m_nAge(nAge), m_bIsMale(bIsMale)  

     {  

     }  

 }; 



Baseball.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream> 

#include <string>  
#include "Person.h"
using namespace std;


 class BaseballPlayer : public Person  

 {  

 public:  

     double m_dBattingAverage;  

     int m_nHomeRuns;  

    

    BaseballPlayer(double dBattingAverage = 0.0, int nHomeRuns = 0): m_dBattingAverage(dBattingAverage), m_nHomeRuns(nHomeRuns)  

    {  

     }  

 }; 


main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream> 
#include <string> 

#include "Person.h"
#include "Baseball.h"

using namespace std;

 


 int main()  

 {  

     // Create a new BaseballPlayer object  

     BaseballPlayer cJoe;  

     // Assign it a name (we can do this directly because m_strName is public)  

     cJoe.m_strName = "Joe";  

     // Print out the name  

     cout << cJoe.GetName() << std::endl;  

    

     return 0;  

 } 
Baseball.h includes Person.h which includes Baseball.h which includes Person.h which includes ....

get the point?

Two things. Header files should have #include guards around them. Secondly, doing that will yield other compile
errors since you have an #include cycle. From the looks of it, Person.h does not need to include Baseball.h.

Topic archived. No new replies allowed.