无法直接分配抽象类的实例,因为它们包含未实现的纯虚拟函数。为了创建一个抽象类的对象,您需要创建一个派生类,并实现所有纯虚拟函数。下面给出一个示例:
class AbstractClass {
public:
virtual void AbstractMethod() = 0; // pure virtual function
};
class DerivedClass : public AbstractClass {
public:
void AbstractMethod() override {
// implementation
}
};
int main() {
AbstractClass *object;
DerivedClass derivedObject;
object = &derivedObject; // okay, because DerivedClass is a concrete implementation of AbstractClass
return 0;
}
上一篇:allocate_tokens_for_local_replication_factor如何工作?
下一篇:AllocatingLargeTensoronmultipleGPUsusingDistributedLearninginKeras