这里是一个产生错误我的例子代码:
struct Impl
{
int data_size_;
int find(int var){return 0;}
int get(int rowid){return 0;}
};
class Container
{
public:
Container() {}
virtual ~Container() {}
virtual int get_size() = 0;
virtual int get(int rowid) = 0;
};
class SortedContainer : virtual public Container {
public:
virtual int find(int var) = 0;
};
class ContainerImpl : public Container
{
protected:
Impl impl_;
public:
int get_size() {return impl_.data_size_;}
int get(int rowid) {return impl_.get(rowid);}
};
class SortedContainerImpl
: public SortedContainer, public ContainerImpl
{
private:
typedef ContainerImpl Base;
public:
int find(int var){return Base::impl_.find(var);}
};
ContainerImpl ci;
SortedContainerImpl sci;
看来“SortedContainerImpl”时出现错误“ContainerImpl”是好的。
克++抱怨:
example_b.cpp:42:21: error: cannot declare variable ‘sci’ to be of abstract type ‘SortedContainerImpl’
example_b.cpp:32:7: note: because the following virtual functions are pure within ‘SortedContainerImpl’:
example_b.cpp:13:15: note: virtual int Container::get_size()
example_b.cpp:14:15: note: virtual int Container::get(int)
我为了重用get_size()和get(INT)inheret SortedContainerImpl从ContainerImpl
我不熟悉C ++,这是什么问题的性质,我该如何解决?
感谢所有。