В классах Cell и Node надо сделать поинтеры друг на друга. Гугл сказал нужно Forward referenz делатъ, но что-то я так и не допёр :(
Исходники таковы:
cell.h
CODE |
#ifndef _cell_h_ #define _cell_h_ #include "Node.h" class Cell { public: int status; //0-int,1-bdry,2-outside double _value; Cell * Neighbours[2]; Node * NodePointer; Cell(double value); Cell(); ~Cell(); }; #endif /* _cell_h_ */ |
cell.cpp
CODE |
#include <iostream> #include <list> #include <map> #include <vector> #include <fstream> #include "Cell.h" using namespace std; Cell::Cell(double value): _value(value){}; Cell::Cell(){}; Cell::~Cell(){}; |
Node.h
CODE |
#ifndef _node_h_ #define _node_h_ #include "Cell.h" class Cell; class Node { public: int _eventtyp; //0 - Node, 1,2,... - leaf bool _isleaf; //samplingtest Cell *_CellPointer; //Null - if Node Node * Neighbours[2]; double _NodeRate; double _NodeValue; int _Num; //double _NodeRightRate; Node *_ParentNode, *_nLeft, *_nRight; Node(int Num,double NodeValue, double NodeRate, bool isleaf); Node(Node* pLeftChild, Node* pRightChild); Node(); ~Node(); inline double getRate() {return _NodeRate;} inline bool operator <(const Node &other) const{return _NodeRate<other._NodeRate;} }; #endif /* _node_h_ */ |
Node.cpp
CODE |
#include <iostream> #include <list> #include <map> #include <vector> #include <fstream> #include "Node.h" //#include "Cell.h" using namespace std; Node::Node(int Num,double NodeValue, double NodeRate, bool isleaf): _Num(Num),_NodeValue(NodeValue),_NodeRate(NodeRate),_nLeft(NULL),_nRight(NULL), _isleaf(isleaf) { _eventtyp=0; //_NodeRightRate=_NodeRate; } Node::Node(Node* pLeftChild, Node* pRightChild): _NodeRate(pLeftChild->_NodeRate+pRightChild->_NodeRate),_nLeft(pLeftChild),_nRight(pRightChild),_isleaf(false) { //_NodeRightRate=pRightChild->_NodeRate; } Node::Node(){ _CellPointer = new Cell; }; Node::~Node(){}; |
В DA создаётъся обект Node и Cell и поинтерывают друг на друга.
Ну что-то я запутался во всём этом перекрёстном поинтерование.
Заранее спасибо за помощь