私は C++ プログラミングの初心者で、C++ でシーン グラフを実装しようとしています。
スーパー クラス (および抽象クラス) である Node クラスと、Geometry、Group、Transformation などのいくつかの子クラスが必要です。サブクラス オブジェクトのいずれかがノードになるグラフを実装する必要があります。ノードごとに 1 つまたは複数の子が存在する可能性があります。(共通のメソッドと属性だけでなく、サブクラスには異なるメソッドと属性があります。)
タイプに関係なく、ノードを追加、削除し、共通のメソッドを実行できるグラフを作成する必要があります。
そのようなグラフを実装するためのアイデアや方法論を共有してもらえますか?
EDIT : これは私の作品のサンプル定義です。(ヘッダーの内容を追加するだけですが、実装が必要な場合は提供します。)
node.h
using namespace std;
#include <cstdio>
#include <string>
#include <vector>
#ifndef NODE_H
#define NODE_H
class Node{
public:
Node();
virtual ~Node() = 0;
Node(string name);
string getName();
void setName(string name);
vector<Node*> getChildrenNodes();
size_t getChildNodeCount();
Node* getChildNodeAt(int i);
void setChildernNodes(vector<Node*> children);
void addChildNode(Node* child);
virtual string getNodeType()=0; // to make this class abstract
protected:
string name;
vector<Node*> children;
};
#endif
ジオメトリ.h
class Geometry : public Node {
public:
Geometry();
~Geometry();
string getNodeType();
// Method overrides and other class specific methods.
};
グラフ.h
#include "node.h"
class Graph{
public:
Graph();
~Graph();
void addNode(Node* parent,Node* child);
void addNode(Node* child);
Node* getRoot();
private:
Node* root;
};
これは私のmain.cppです
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include "node.h"
#include "graph.h"
int main(){
Graph sg;
Geometry g1;
sg.addNode(g1); // error: no matching function for call to ‘Graph::addNode(Geometry&)’
return 0;
}
できれば、どこが間違っていたのかを示してください。