Hi all,
I have a more philosophical question which I think might help me to better understand the interest of pointers in C++. Indeed, my background is mainly Perl and a bit of Java.
I am currently implementing (as an exercise and because I work in this field) a class to play with graph theory. At the moment, I have three classes : Node, Edge and Graph.
To your opinion, an edge has to be an object like the following code (where the nodes source and target that defines it are pointers to the nodes) or where the nodes are the object really.
class Edge {
public:
Edge(Node*, Node*); // constructor (specify only the source and the target nodes
Edge(Node*, Node*, string, double, string); // constructor (specify the source and target nodes, the color, the weight and the name)
void setSourceAndTarget(Node*, Node*); // set the source node and the target node
// blabla
private:
Node *source; // source node
Node *target; // target node
// blabla
};
I have the same kind of problem with my Graph class. It class contains two set attributes : edgesSet and nodesSet. Do these set have to contain pointers to the edges and nodes or the objects directly!
Thank you for your opinion!