Search code examples
c++observer-pattern

Why does my code result in "cannot instantiate abstract class"?


This is the line where the error occurs:

this->_tbfCmdHandler.reset(new Bar()); 

facade_impl.cpp(202): error C2259: 'FOO::Bar' : cannot instantiate abstract class
due to following members:
'void Subscriber::update(T)' : is abstract with
T=char &

observer.h(66) : see declaration of 'Subscriber::update'
with
T=char & 'void Subscriber::update(T)' : is abstract with
T=const char &

observer.h(66) : see declaration of 'Subscriber::update'
with
T=const char & ]

This is the declaration for Facade::Implementation

namespace FOO
{
class Facade::Implementation 
                :public Subscriber<const char& >                     
{

facade.cpp

FOO::Facade::Facade () : impl (new Implementation)
{

    Singleton<SPM::Facade>::instance ();
}


The update functions:
    void update( const char *aMsg)   
    {
        printf("foo");
    }; 

I hope this helps to figure out where I can find the error.


Solution

  • You are inheriting from an abstract class, so you need to implement the void update( const char& ) function inside class Facade::Implementation.

    You did define an update function, but it is not related in any way to Subscriber. You have to put it inside your implementation.