【发布时间】:2015-11-19 07:05:58
【问题描述】:
我有一个包含指针的网络类。我想为它重载赋值运算符。
class Network
{
public:
Network();
Layer *Layers; //The total layers in network
unsigned long net_tot_layers; //Number of layers
unsigned long *net_layers; //Array which tells no. of neurons in each layer
Network::Network(double learning_rate, unsigned long layers[], unsigned long tot_layers);
};
构造函数
Network::Network(double learning_rate, unsigned long layers[], unsigned long tot_layers) {
net_layers = new unsigned long[tot_layers]; //Initialize the layers array
Layers = new Layer[tot_layers];
for (unsigned i = 0; i < tot_layers; i++) {
net_layers[i] = layers[i];
Layers[i].Initialize(layers[i]); //Initialize each layer with the specified size
}
net_tot_layers = tot_layers;
}
如何通过深拷贝正确重载赋值运算符?
请帮忙,想用向量替换所有指针...
class Layer
{
public:
Layer();
~Layer();
Neuron *Neurons;
void Initialize(unsigned long size);
};
class Neuron
{
public:
Neuron(); // Constructor
~Neuron(); // Destructor
Link* Links; //Links
Neuron(); // Constructor
};
class Link {
public:
Link(double weight = 0.0); // Constructor
~Link(); // Distructor
double weight; //Weight of the link
};
要用向量替换所有指针,我必须做哪些更改/添加>
【问题讨论】:
-
使用矢量,您将节省大量时间。
-
谢谢,会试试的。还有一些问题。
标签: c++ operator-overloading assignment-operator