Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a graph with different types of Nodes?
    text
    copied!<p>I'm a very much new to C++ programming and I'm trying to implement a Scene Graph in C++.</p> <p>There should be a Node class, which is the super class (and an abstract class) and some child classes like Geometry, Group, Transformation etc. I need to implement a graph, where either of sub class objects can be nodes. There can be one or many children per node. (There are common methods and attributes as well as different methods and attributes in sub classes.)</p> <p>I need to create a graph where I can add,remove nodes and execute their common methods regardless to their type.</p> <p>Can anyone please share any ideas or methodologies to implement such graph?</p> <p>EDIT : This is a sample definitions of my work. (I only add the header contents. But if the implementation is needed, I will provide.)</p> <p>node.h</p> <pre><code>using namespace std; #include &lt;cstdio&gt; #include &lt;string&gt; #include &lt;vector&gt; #ifndef NODE_H #define NODE_H class Node{ public: Node(); virtual ~Node() = 0; Node(string name); string getName(); void setName(string name); vector&lt;Node*&gt; getChildrenNodes(); size_t getChildNodeCount(); Node* getChildNodeAt(int i); void setChildernNodes(vector&lt;Node*&gt; children); void addChildNode(Node* child); virtual string getNodeType()=0; // to make this class abstract protected: string name; vector&lt;Node*&gt; children; }; #endif </code></pre> <p>geometry.h</p> <pre><code>class Geometry : public Node { public: Geometry(); ~Geometry(); string getNodeType(); // Method overrides and other class specific methods. }; </code></pre> <p>graph.h</p> <pre><code>#include "node.h" class Graph{ public: Graph(); ~Graph(); void addNode(Node* parent,Node* child); void addNode(Node* child); Node* getRoot(); private: Node* root; }; </code></pre> <p>This is my main.cpp</p> <pre><code>#include &lt;cstdio&gt; #include &lt;stdio.h&gt; #include &lt;iostream&gt; #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&amp;)’ return 0; } </code></pre> <p>If you can, show where I went wrong.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload