1

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{
    // ?
};
OliverXH
  • 19
  • 3

1 Answers1

0

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; }
Tanveer Badar
  • 5,438
  • 2
  • 27
  • 32
  • 2
    This is factually correct. It does not answer the question: *how to write WebIDL especially about class Base?* – Eljay Feb 04 '22 at 16:28