This question already has an answer here:
I have two header files as follows:
"elements.h"
#include <vector>
#include "nodes.h" // circular inclusion!!!
#ifndef ELEMENTS_H
#define ELEMENTS_H
class Element {
public:
// constructors and methods...
private:
std::vector<Node*> nodes;
};
#endif // ELEMENTS_H
"nodes.h"
#include <vector>
#include "elements.h" // circular inclusion!!!
#ifndef NODES_H
#define NODES_H
class Node {
public:
// constructors and methods...
private:
std::vector<Element*> elements;
};
#endif // NODES_H
How can I solve this problem (to keep the same dependencies between the classes) without circular inclusion? And in the same time to keep this declarations in different files "elements.h" and "nodes.h". Is this possible?
Aucun commentaire:
Enregistrer un commentaire