Note that there are some explanatory texts on larger screens.

plurals
  1. POSegmentation fault and getter issue
    text
    copied!<p>i have an assignment that tracks persons, and for now i need to make the crud operations. When i try to access the dynamic array, the getter for person's id works, but the one for persons phone returns "segmentation fault", and the one for person's name shows nothing.</p> <pre><code>//the main.cpp test that gives the following error Controller ctrl(repp,repa,valp,vala); ctrl.addPerson(1,"Name","0744000000","Adress"); ctrl.show(); //controller show method, repp - instance of repository in controler void Controller::show() { repp-&gt;show(); } //repository show method, which doesn't work void PersonInMemoryRepository::show() { for(int i=0; i &lt; pers.getSize(); i++) cout&lt;&lt;pers.get(i)-&gt;getName()&lt;&lt;endl; } //getById method in repository const Person* PersonInMemoryRepository::getById(int id) { for (int i = 0; i &lt; pers.getSize(); i++) { if (pers.get(i)-&gt;getId() == id) { return pers.get(i); } } return NULL; } //the Person class class Person { public: Person(int i, string n, string p, string a); const string&amp; getName() const { return name; } const string&amp; getPhone() const { return phone; } const string&amp; getAdress() const { return adress; } int getId() const { return id; } ~Person(); private: int id; string name; string phone; string adress; }; //pers.get(i) template&lt;typename Element&gt; Element DynamicArray&lt;Element&gt;::get(int poz) { return elems[poz]; } </code></pre> <p>Thanks in advance. </p> <p>Update: When it's on the line cout&lt;getName(); . pers.get(i) works good, it's a Person* type vector, and when i dereference it in the debugger, it has the right values, but at the ->getName() it says "invalid number 0 of repetitions". </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload