1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
#include <iostream> #include <list> #include <iterator> class neuron{ public: double w; std::list<neuron*> frn; ~neuron(){while(!frn.empty()) delete frn.front(), frn.pop_front();} }; class layer{ public: unsigned short n; std::list<neuron*> dom; layer(unsigned short); ~layer(){while(!dom.empty()) delete dom.front(), dom.pop_front();} }; layer::layer(unsigned short a){ n = a; for(unsigned short i; i < a; i++){ dom.push_back(new neuron); }; }; int main() { std::list<layer*> neuron_net; unsigned short ailayers = 9; for(unsigned short i = 0; i < ailayers; i++){ neuron_net.push_back(new layer(i)); }; for(std::list<layer*>::iterator it = neuron_net.begin(); it != neuron_net.end(); it++){ std::cout<<"\n neuron_net->layer->n = "<<(*it)->n; for(std::list<neuron*>::iterator jt = (*it)->dom.begin(); jt != (*it)->dom.end(); jt++){ (*jt)->w = 1.2345; std::cout<<"\n neuron_net->layer->dom->w = "<<(*jt)->w; }; }; while(!neuron_net.empty()){delete neuron_net.front(); neuron_net.pop_front();};//delete pointers from list std::cin>>ailayers;//system pause return 0; };
for(auto it = neuron_net.begin(); it != neuron_net.end(); it++){
for(auto jt = (*it)->dom.begin(); jt != (*it)->dom.end(); jt++){
new
delete
123456789101112131415161718192021222324252627282930313233
#include <iostream> #include <list> class Neuron { public: double w {}; std::list<Neuron> frn; }; class Layer { public: unsigned short n {}; std::list<Neuron> dom; Layer(unsigned short a) : n(a), dom(a, Neuron {}) {} }; int main() { const unsigned short ailayers { 9 }; std::list<Layer> neuron_net; for (unsigned short i {}; i < ailayers; neuron_net.emplace_back(i++)); for (auto& [n, dom] : neuron_net) { std::cout << "\n neuron_net->layer->n = " << n; for (auto& [w, frn] : dom) { w = 1.2345; std::cout << "\n neuron_net->layer->dom->w = " << w; } } }