regarding headers(unknown type name!,nested too deep;y)

hello there hope you doing well. so i have this problem when i am trying to make a declaration for a child class in a parent class it gives me this error:
unknown type name 'Gold'and that is because i haven't include the headers. However, when i include the the headers it gives me the error nested too deeply!!

here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 

#ifndef GOLD_H
#define GOLD_H

 #include"Events.h"

class Gold: public Events {
    
private:
    char gold;
    
    
public:
    Gold();
  void set_gold();
  char get_gold();
    
};

#endif  


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#include"Gold.h"

Gold::Gold(){
    gold='$';
    
}

  void Gold::set_gold(){
      gold='$';
  }
  char Gold::get_gold(){
      
      return gold;
  }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  
#include"Gold.h"

#ifndef EVENTS_H
#define EVENTS_H
class Events{
    
private:
Gold *g; 
public:
    
    
};

#endif 

]


" i am trying to make a declaration for a child class in a parent class"
If I understand you. You cannot do the above. The parent class does not "know" about the child class.
Are you sure this relationship makes sense. What is an "events" and is a "gold" object really an "events" (whatever that is)?

You can make it compile by putting a forward declaration of Gold in Events.h instead of including the header file.

1
2
#include "Gold.h"
class Gold;

If the Events class use the Gold class (create objects, call member functions, etc.) you'll have to include Gold.h from Events.cpp.
Last edited on
Topic archived. No new replies allowed.