【问题标题】:Nested observer template嵌套观察者模板
【发布时间】:2013-11-14 05:57:49
【问题描述】:

我需要使用通知类观察模板。我使用此代码:

#include <Poco/Notification.h>
#include <Poco/Observer.h>
#include <Util/RegisterObserver.h>
namespace RPC {
class ParseErrorNotify : public Poco::Notification{
public:
    ParseErrorNotify();


private:
    //std::string m_message;
};

template <class C>
class Observer:public Poco::Observer<C,ParseErrorNotify>{
    public:
        typedef Poco::Observer<C,ParseErrorNotify> Base;
        Observer(C& object, Base::Callback method):Base(object,method){}
};

}

但是编译时出错:

ParseErrorNotify.h:20:35: 错误:'Poco::Base::Callback' 不是类型

我使用的是 gcc 版本 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)。太奇怪了,因为用MSVC2010 on win compile ok。

【问题讨论】:

    标签: c++ poco-libraries


    【解决方案1】:

    这并不奇怪。你应该使用typename

    Observer(C& object, typename Base::Callback method):Base(object,method){}
    

    因为Callback 是从属名称。 阅读此Where and why do I have to put the "template" and "typename" keywords? 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 2023-04-10
      • 1970-01-01
      • 2017-06-15
      相关资源
      最近更新 更多