Circular dependencies and headers

Hi,

To practice classes, I am writing two classes, one representing a directory and other representing a file. Here is how they look:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// This is directory.h
#include <set>
#include <string>
#include "file.h"
using std::set;
using std::string;

class directory
{
    public:
        directory (string dirname, directory * parentptr);
        directory (string dirname, directory * parentptr, set<directory *> dirset);
        directory (string dirname, directory * parentptr, set<file *> fileset);
        directory (string dirname, directory * parentptr, set<directory *> dirset, set<file *> fileset);
        string getName();
        bool addFile(string filename);
        bool addDir(string dirname);
    private:
        string name;
        directory *parent;
        set<directory *> dirs;
        set<file *> files;
};


1
2
3
4
5
6
7
8
9
10
11
12
#include <set>
#include <string>
#include "directory.h"

using std::string;
class file
{

    private:
        string name;
        directory * parent;
};


This causes circular includes. How to get around this? What is recommended way to handle circular dependencies?
Topic archived. No new replies allowed.