c++ - prints strange numbers from memory -


i have list(dynamic vector) contains medicines , want print medicines list prints numbers memory. example:

give medicine's id: 1 give medicine's name:alg give medicine's concentration: 30 give medicine's quantity: 40 

prints:

the medicine's id is: 4215400 medicine's name is:  medicine's concentration is: 3.47235e+230 medicine's quantity is: 2686544 

these print functions:

 void console::printmedicine(medicine* m){         int id = m->getid();         string name = m->getname();         double concentration = m->getconcentration();         int quantity = m->getquantity();         cout<<"\nthe medicine's id is: "<<id<<"\n";         cout<<"the medicine's name is: "<<name<<"\n";         cout<<"the medicine's concentration is: "<<concentration<<"\n";         cout<<"the medicine's quantity is: "<<quantity<<"\n";     }      void console::printallmedicines(){         dynamicvector<medicine*>* medlist = ctrl->getallmeds();         for(int i=0; < medlist->getlen(); i++){             medicine* m = medlist->getelementatposition(i);             printmedicine(m);         }     } 

this getelementatposition function:

template <typename element> element dynamicvector<element>::getelementatposition(int pos){     return this->elems[pos]; } 

this medicine class, private part:

class medicine{ private:     int id, quantity;     double concentration;     string name; 

and declaration of medlist in repository:

class repository{     public:         dynamicvector<medicine*>* medlist; 

constructor , getters in medicine class:

  medicine::medicine(){ //implicit constructor         this->id=0;         this->concentration=0;         this->name="";         this->quantity=0;     }      medicine::medicine(int id, string name, double concentration, int quantity){ //constructor parameters         this->id=id;         this->name=name;         this->concentration=concentration;         this->quantity=quantity;   int medicine::getid(){     return this->id; }  string medicine::getname(){     return this->name; }  double medicine::getconcentration(){     return this->concentration; }  int medicine::getquantity(){     return this->quantity;          } 

the getallmeds , getall functions:

dynamicvector<medicine*>* controller::getallmeds(){     return repo->getall(); }  dynamicvector<medicine*>* repository::getall(){     return medlist; } 

i tried hours fix can't understand where's problem. doing wrong?

i'm assuming medicine instances created getallmeds(). sure passing values constructor? values seeing uninitialized memory me. same strange values every time or change?


Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -