I am developing a project in C++ under Ubuntu 11.10 using the latest version of NetBeans. I'll only post minimal parts of the code relevant to the problem. Let's say I have the following code for a graph kind of problem:
typedef map<Node*, double, DereferenceCompare> Transitions;
class Node {
int _nodeNumber;
Transitions _transitions;
}
Each Node object holds a map of pointers to other Node objects. Now we have:
typedef set<Node*, DereferenceCompare> Nodes;
class Network {
Nodes _network;
}
The problem: I am at a loss about writing a copy constructor for the class Network. What I am trying to achieve is to be able to do the following:
Network n1;
Network n2(n1);
//Have both n1 and n2 identical in structure but distinct in memory (deep copy).
Am I right in the following assumption: if I write a copy constructor for the Node class it would need to also copy the Transitions container. The Transitions container at that moment would hold pointers to the old nodes as the new ones do not exist yet.
This is my first post here. I hope I provided clear and sufficient information. I can further clarify if I was not coherent enough with my problem. Any help would be greatly appreciated.