Thursday 15 January 2015

c++ - Segmentation fault with iterator on object vector -


Access to class parameters and functions via an operator fails, when using both - & gt; And *. Finding a lot of threads to no avail will not allow me to submit the question, unless more details are added, Hmm, co-connection means and the reconstruction construction and pointer reference have been done throughout the day.

Snip:

  vector & lt; Axon & gt; :: Iterator AIT; AIT = axl.begin (); Const Neuron * Co = AIT-> gt_conn ();   

Diet optimization code:

  #include & lt; Iostream & gt; # Include & lt; Vector & gt; using namespace std; Class Neuron; Class Exxon; Class Neuron {Buddy Class Exxon; Public: Neuron (Int); Zero excited (double); Zero Connect (Constant Neuron *); // void grow_ax (); Private: Double _ axis; Of vector & lt; Exxon & gt; Axle; }; Class Exxon {Friend class neuron; Public: Exxon (); Constant Neuron * get_conn (); Private: Double Condon; // conductor sensation neuron * connection; }; Neuron :: Neuron (Int. NewX) {_exc = 0; Of vector & lt; Exxon & gt; Axel (Newmax, Exxon); Exxon :: Exxon () {cond = 1; Connection = 0; } Neutral Neuron :: Connect (Constant Neuron * NP) {Vector & lt; Axon & gt; :: Iterator AIT; AIT = axl.begin (); Const Neuron * Co = AIT-> gt_conn (); // error is here, // if (AIT-> Connection == 0) do not work on // AIT-> Connection = NP; & Lt; ===} Const Neuron * Axon :: get_conn () {Return Connection; } Int main () {neuron n1 = neuron (1); Neuron N2 = Neuron (0); Neuron * N2P = & amp; nbsp; N2; N1.connect (n2p); }   

Thanks in advance

  ait = axl .start (); Const Neuron * Co = AIT-> gt_conn (); There is no element in   

Excel , therefore, axl.begin () == axl.end () and you 're Delete it from std :: vector :: end () is an undefined behavior .

Look at your manufacturer:

  Neuron :: Neuron (integer number) {_exc = 0; Of vector & lt; Exxon & gt; Axel (Newmax, Exxon); // This is the declaration of the local object, which will be destroyed at the end of the constructor)   

Note also, this:

  Neuron N1 = Neuron (1); Neuron N2 = Neuron (0);   

should be

  neuron N1 (1); Neuron N2 (0);    

No comments:

Post a Comment