g++ “because the following virtual functions are pure” with abstract base class

Your SortedContainerImpl class has two separate Container base classes. One is virtual (via the SortedContainer class) and the other is non-virtual (via the ContainerImpl class).

SortedContainerImpl has concrete implementations of Container::get_size() and Container::get(int) for the base that comes in from ContainerImpl, but not for the virtual base that comes in via SortedContainer.

One way to fix the problem is to give concrete implementations in SortedContainerImpl:

class SortedContainerImpl
  : public SortedContainer, public ContainerImpl
{
private:
  typedef ContainerImpl Base;
public:
  int find(int var){return Base::impl_.find(var);}

  int get_size() {return ContainerImpl::get_size();}
  int get(int rowid) {return ContainerImpl::get(rowid);}
};

Another way would be to make Container a virtual base class of ContainerImpl, so SortedContainerImpl would only get the one, virtual, base Container:

class ContainerImpl : virtual public Container
{
protected:
  Impl impl_;
public:
  int get_size() {return impl_.data_size_;}
  int get(int rowid) {return impl_.get(rowid);}
};

Leave a Comment