简体   繁体   中英

Abstract class pointer in C++

The abstract C++ class is a class for which at least one pure virtual method exits.(ie one can`t instantiate it) Why and when the pointer to the abstract class should be used? The only situation I can think about - is classical polymorphic base class pointer which behaves differently based on dispatch table. Are there any additional reasons?

Upd. Is class abstract if its constructor is private?

The only situation I can think about - is classical polymorphic base class pointer

Yes, that's exactly what abstract classes are used for, and the only non-bizarre use for them.

Is class abstract if its constructor is private?

No. That class can still be instantiated, but only by its members or friends. An abstract class can't be instantiated at all.

You would use base class pointers to store a collection of disparate objects. Then you could do operations on the items as a group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM