- #1
Hepth
Gold Member
- 464
- 40
I'm making a basic neural network, and I haven't programmed in an object oriented way since java in undergraduate. Everything lately has been c and fortran 77.
I have an object that is a "Network"
In addition to functions and locals, it includes a pointer to an array of another object "Layer"
Each Layer includes a pointer to an array of "Neuron"
Each Neuron includes a pointer to an array of "Connection"
Connection just has a double "val".
How do I create an operator and copy constructor such that when I have
And then
A.Layers[0].Neurons[0].Connections[0].val
B.Layers[0].Neurons[0].Connections[0].val
should be different. As it stands, the basic shallow copy makes copies of the pointer locations, rather than the deep values contained. So A.Layer and B.Layer point to the same location, so any changes to B makes changes to A. I want to make a NEW duplicate, that does a deep copy.
Do I need to go to each class and add a more deep copy constructor with rules for EVERY pointer/array/object in that class, and how to copy itself deeply?
It feels like a lot of work, where if inside say Neuron class I have a bunch of different pointers, I would have to make the copy constructor copy the value of each one?
Sorry if its not clear, I have an idea of what I'm doing but I'm having trouble getting it done. It also doesn't help that I am working off of someone elses template to a very basic degree.
I have an object that is a "Network"
In addition to functions and locals, it includes a pointer to an array of another object "Layer"
Each Layer includes a pointer to an array of "Neuron"
Each Neuron includes a pointer to an array of "Connection"
Connection just has a double "val".
How do I create an operator and copy constructor such that when I have
Code:
Network A;
A.Randomize(); //Sets everything to random values at the Connection level
Network B = A; //Here I want to define a copy
B.Randomize(); //Randomize B
And then
A.Layers[0].Neurons[0].Connections[0].val
B.Layers[0].Neurons[0].Connections[0].val
should be different. As it stands, the basic shallow copy makes copies of the pointer locations, rather than the deep values contained. So A.Layer and B.Layer point to the same location, so any changes to B makes changes to A. I want to make a NEW duplicate, that does a deep copy.
Do I need to go to each class and add a more deep copy constructor with rules for EVERY pointer/array/object in that class, and how to copy itself deeply?
It feels like a lot of work, where if inside say Neuron class I have a bunch of different pointers, I would have to make the copy constructor copy the value of each one?
Sorry if its not clear, I have an idea of what I'm doing but I'm having trouble getting it done. It also doesn't help that I am working off of someone elses template to a very basic degree.