"Observer-Pattern" in C++ using Smart Pointer ? -


professionals out there,

this first time i'm posting question board helped me out lot in past. i'm still programming novice , have been trying learn lot programming & software development in last few months.

i tackled topic "c++11-smart pointers" , decided rewrite design patterns learned few weeks earlier, including the"observer pattern" using shared_ptr & weak_ptr resource management.

when trying write simple implementation of observer pattern (like in head first's design pattern or design patterns e.gamma), using interface-class both observable subjects , observers, , 1 concrete class each, received various error messages visual studio. don't understand how combine shared_ptr , weak_ptr in pattern, might due fact still don't understand the combination of both.

unfortunatelly, thorough search on internet didn't provide me simple example of "observer-pattern using smart-pointer" can serve orientation me.

i therefore wondering, if 1 of guys know find such simple implmentation or kind provide me 1 of own. both really helpful :-)

thanks lot

coderandi

the observer pattern typical example of case smart pointers (at least usual candidates) inappropriate. neither subject nor object "own" 1 another; each has own lifespan. in fact, 1 frequent use of observer pattern when object has pointer object doesn't own. registers observer, informed when observed object destructed.

it sounds me you're attacking entire thing backwards. have solution (smart pointers), , you're trying make every problem fit it. never works.


Comments