this question has answer here:
- which kind of pointer use when? 5 answers
good day, everybody!
here stuck: have 3 concrete classes: computer, peripheral , person. computer , peripheral both extend class device.
device has private member device.owner: person, should store kind of reference owner of device, , public function device.getowner(): person.
on other hand, person has own private members person.peripherals , person.computers , public functions person.get() ... etc.
is there design patterns build these connections between classes?
without transferring direct ownership! (the computer has no rights kill instance of person etc. why beware of using pointers)
but if instances of computer change owner must disappeared list of computers of previous owner , appeared in list of new owner. same thing peripheral.
please, ask questions if have some. probably, explanation of situation poor. sorry lang mistakes.
you can use std::unique_ptr ensure single reference exists object. change ownership use std::move.
std::unique_ptr<device> deviceptr(new device()); std::unique_ptr<device> deviceptr2(std::move(deviceptr)); each person have it's unique pointer(s).
Comments
Post a Comment