class ASubject { // 让我们跟踪我们观察到的所有商店 std :: vector< iobserver *>列表; public : void Attach(IObserver * product); void 分离(IObserver * product); void 通知( float 价格); }; 和商店应该从IObserver公开派生? class 购物: public IObserver { // 商店名称 std :: string name; float 价格; public : Shop(std :: string n); void 更新( float 价格); ~Shop(){std :: cout<< In~Shop()<< \ n;} }; 解决方案 如果有任何问题的Rahul Rajat Singh [ ^ ],请张贴在留言板上他的文章 [ ^ ](在页面底部)。 Hallo Rahul Rajat Singh,I have small question regarding Observer Pattern in C++.Isn't it the class ASubject{ //Lets keep a track of all the shops we have observing std::vector<iobserver*> list;public: void Attach(IObserver *product); void Detach(IObserver *product); void Notify(float price); };and Shop should be publicly derived from IObserver ?class Shop : public IObserver{ //Name of the Shop std::string name; float price;public: Shop(std::string n); void Update(float price); ~Shop() { std::cout << " In ~Shop()" << "\n";}}; 解决方案 If you have any question to Rahul Rajat Singh[^], please post it in message board to His article[^] (on bottom of page). 这篇关于关于观察者模式的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 22:24