Search code examples
c++abstract-classawesomium

How do I set a listener in Awesomium? ("Field type 'Listener' is an abstract class" error)


I've been trying to get a Awesomium::WebViewListener working, but whenever I try to allocate the Listener object I get a "Field type 'Listener' is an abstract class" error.

Here's my code:

class Listener : public Awesomium::WebViewListener
{
public:
    void onCallback(Awesomium::WebView* caller,
                    const std::wstring& objectName,
                    const std::wstring& callbackName,
                    const Awesomium::JSArguments& args)
    {
        std::cout << "Hello!" << std::endl;
    }
};

// In the GUI class
Listener listener; // Field type 'Listener' is an abstract class
view->setListener(&listener);

How am I supposed to set the listener if I can't allocate a Listener-object? I've tried using boost::shared_ptr which doesn't produce any errors but the onCallback()-function never gets called.


Solution

  • It could be two variants:

    1. Awesomium::WebViewListener contains more then one abstract method. If so - you should implement them all to create an instance of derived class `Listener' (bash.d said about it)
    2. Awesomium::WebViewListener::onCallback arguments list should be exatly equal to your's one. If not so, then you added this method to Listener, but not implemented base abstract onCallback