プログラムで循環依存に直面し、ポインターと前方宣言を使用して解決しました。dn.hpp
この目的のためにファイルを作成しました。ジェネリックではなく共有ポインターに移行するまでは、すべて問題ありませんでした。で共有ポインタの typedef を作成しましたdn.hpp
。すべてが一般的なポインタ(コメントアウト)で機能しますが、共有では機能しません。
エラーが返されます: フィールド 'parentGraph' の型が不完全です node.h 行 21
(ブースト1.47でmingwを使用しています)
この問題を解決するのを手伝ってください。
これが私のコードの簡略版です:
dn.hpp
// forward declarations
#include <map>
#include <list>
#include <boost/shared_ptr.hpp>
class graph;
typedef boost::weak_ptr<graph> graph_wp;
typedef boost::shared_ptr<graph> graph_sp;
//typedef graph* graph_wp;
//typedef graph* graph_sp;
class node;
typedef boost::weak_ptr<node> node_wp;
typedef boost::shared_ptr<node> node_sp;
//typedef node* node_wp;
//typedef node* node_sp;
typedef std::list<node_sp> nodes_t;
class edge;
typedef boost::weak_ptr<edge> edge_wp;
typedef boost::shared_ptr<edge> edge_sp;
//typedef edge* edge_wp;
//typedef edge* edge_sp;
typedef std::list<edge_sp> edges_t;
typedef std::list<edge_wp> edgeList_t;
グラフ.h
#ifndef GRAPH_H_
#define GRAPH_H_
#include "node.h"
#include "edge.h"
#include "dn.hpp"
class graph
{
public:
node* createNode();
protected:
nodes_t nodes;
edges_t edges;
};
#endif /*GRAPH_H_ */
node.h
#ifndef NODE_H_
#define NODE_H_
#include "graph.h"
#include "edge.h"
#include "dn.hpp"
class node
{
public:
node();
node(graph_wp n);
node(const graph_wp& net);
virtual ~node();
edge_wp createChild();
protected:
graph_wp parentGraph;
edgeList_t edges;
};
#endif /* NODE_H_ */
edge.h
#ifndef EDGE_H_
#define EDGE_H_
#include "node.h"
#include "dn.hpp"
class edge
{
public:
edge(node_wp src,node_wp tgt);
virtual ~edge();
private:
node_sp source;
node_sp target;
};
#endif /* EDGE_H_ */
main.cpp
#include "graph.h"
int main() {
graph n;
return 0;
}