Is there any methods to solve "unimplemented pure virtual method"

540 Views Asked by At

I'm using Emscripten to build my C++ source code to JavaScript, and I met some problem about how to write correct interface description in WebIDL file.

C++ code example:

class Base
{
public:
    virtual bool is_true() const = 0;
    virtual int get_count() const = 0;
}

class Child: public Base
{
public:
    virtual bool is_true() const
    {
        return true;
    }
    virtual int get_count() const
    {
        return 10;
    }
}

But how to write WebIDL especially about class Base?

interface Base{
    // ?
};
1

There are 1 best solutions below

1
On

You can still provide an implementation of pure virtual functions outside the class definition. For instance, a pure virtual destructor is always called and hence must be implemented by the base.

class Base
{
public:
    virtual bool is_true() const = 0;
    virtual int get_count() const = 0;
}

bool Base::is_true() const { return false; }
int Base::get_count() const { return 0; }