c++ - Passing in References vs. Pointers -
i getting error when pass in newtemp setemergencycontact(). error in regards to:
temp->contact::setemergencycontact(newtemp);
"error: no matching function call 'contact::setemergencycontact(*&contact)'"
so question is: if have create object using pointer, how pass object function uses reference not pointer?
contact generaterandomcontact(){ // name created // generaterandomname() , phone number created // generaterandomnumber(). using above random function, // 50% probability assign new contact emergencycontact // of 1 generated. otherwise leave null (default). // return contact. contact* temp = new contact; temp->contact::changename(generaterandomname()); temp->contact::changenumber(generaterandomnumber()); if(myrand(11) % 2 != 0){ contact* newtemp = new contact; temp->contact::setemergencycontact(newtemp); } return *temp; }
emergency contact function:
void contact::setemergencycontact(contact & _emergencycontact){ contact* changeemergencys = new contact; changeemergencys = emergencycontact->getemergencycontact(); }
dereference it:
temp->setemergencycontact(*newtemp)
Comments
Post a Comment