Overview
Features
Download
Documentation
Community
Add-Ons & Services

Notification event compiler error

Please post support and help requests here.

Notification event compiler error

Postby dbarzo » 29 Mar 2013, 18:18

Hi,

I'm using a notification object like this:

Code: Select all
class NewSessionNotification : public Notification {
public:
  NewSessionNotification(Session::Ptr session) : m_session(session) {};
  Session::Ptr getSession() { return m_session; }
private:
  Session::Ptr m_session;
};


Code: Select all
class SessionFactory : public ISessionFactory
{
public:
  virtual ~SessionFactory() {};

  inline Session* createSession(const IMessageDispatcher* dispatcher) {
    Session* session = new Session(dispatcher);
    m_Notifier.postNotification(new NewSessionNotification(session));
    return session;
  };

  ERROR_CODE AddHandler(ISessionNotifier * pHandler) {
    m_Notifier.addObserver(
        NObserver<ISessionNotifier, NewSessionNotification>(*pHandler, &ISessionNotifier::OnNewSession)
    );
    return EC_NO_ERRORS;
  };
     
  ERROR_CODE RemoveHandler(ISessionNotifier * pHandler) {
    m_Notifier.removeObserver(
        NObserver<ISessionNotifier, NewSessionNotification>(*pHandler, &ISessionNotifier::OnNewSession)
    );
    return EC_NO_ERRORS;
  };

  /// Creates the SessionFactory.
  SessionFactory() {};

private:
  NotificationCenter  m_Notifier;
};


And the handler...

Code: Select all
void ChannelsManager::OnNewSession(const Poco::AutoPtr<NewSessionNotification>& pNf) {
  Session::Ptr s = pNf->getSession();  <---- I get the error here
  s->AddMsgHandler(this);
};


When I compile this, I get the error:
error C2662: 'NewSessionNotification::getSession': unable to convert the pointer 'this' from 'const NewSessionNotification' to 'NewSessionNotification &'
The conversion lose qualifiers

What I wrong?

Regards,
Daniele.
dbarzo
 
Posts: 39
Joined: 14 Jan 2013, 17:15
Location: Italy

Re: Notification event compiler error

Postby alex » 29 Mar 2013, 19:12

dbarzo wrote:What I wrong?

You are calling non-const member function on const reference.
Try redefining your class like this:
Code: Select all
const Session::Ptr& getSession() const { return m_session; }
alex
 
Posts: 1146
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Notification event compiler error

Postby dbarzo » 02 Apr 2013, 10:38

Thanks Alex.
dbarzo
 
Posts: 39
Joined: 14 Jan 2013, 17:15
Location: Italy


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest