【发布时间】:2011-01-16 23:27:26
【问题描述】:
我有一个类接口,它有纯虚方法。在另一个类中,我有一个继承自 Interface 并使其非抽象的嵌套类型。我使用接口作为类型并使用函数来初始化类型,但是我得到,由于抽象类型而无法编译。
界面:
struct Interface
{
virtual void something() = 0;
}
实施:
class AnotherClass
{
struct DeriveInterface : public Interface
{
void something() {}
}
Interface interface() const
{
DeriveInterface i;
return i;
}
}
用法:
struct Usage : public AnotherClass
{
void called()
{
Interface i = interface(); //causes error
}
}
【问题讨论】:
标签: c++ inheritance abstract-class