Hi, I have an abstract class like this:

class Descriptor
        virtual ULONG dispatch(char*, size_t, Stream) = 0;

and I have a subclass like this:

class ConsoleShell : public Descriptor
        ULONG dispatch(char*, size_t, Stream*);

#include "services/console/Console.cpp"

and in Console.cpp:

ULONG ConsoleShell::dispatch(char *cmd, size_t len, Stream *s)
    return (ACE_OS::strcmp(cmd, "quit") == 0) ? s->close() : s->printf(cmd);

So I would think I'm all set to instantiate ConsoleShell, but I gcc gives me this:

/export/home/levk/r6/services/console/Console.cpp: In member function `ULONG
Console<Connection, Address>::start() [with Connection = LSOCKConnection,
Address = ACE_UNIX_Addr]':
/export/home/levk/r6/utility/connection/LSOCKConnection.h:17: instantiated from here
/export/home/levk/r6/services/console/Console.cpp:38: error: cannot allocate an
object of type `ConsoleShell'
/export/home/levk/r6/services/console/Console.cpp:38: error: because the
following virtual functions are abstract:
/export/home/levk/r6/utility/connection/Connection.h:71: error: virtual ULONG
Descriptor::dispatch(char*, unsigned int, Stream)

Where Console.cpp:38 is where I'm trying to instantiate ConsoleShell and Connection.h:71 is Descriptor::dispatch

Am I missing something syntactically from the snippet I just gave you?

Thank you in advance

11 Years
Discussion Span
Last Post by ~s.o.s~

derived class declaration of the pure virtual function must be EXACTLY like that in the base class, minus the "= 0" part. You forgot the word virtual in the derived class. I find it easy to prevent that kind of error by copy-past from base class to derived class.


You forgot the word virtual in the derived class.

I tried that, I still get the same error. BTW, I'm instantiating ConsoleShell using new if that matters at all


THAT WAS IT!!! Thank You!!! I always mess these things up

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.