What is the difference between an abstract class and an interface in C++? How do you implement interface-like behavior?
Show answer and explanation
An abstract class has at least one pure virtual function and may also own state, constructors, non-virtual functions, and implemented virtual functions. C++ has no interface keyword; an interface-like runtime contract is normally an abstract class containing only the required pure virtual operations plus a virtual destructor when deletion through the base is supported. C++20 concepts provide a separate compile-time contract for generic code without inheritance or runtime dispatch.
An abstract class has at least one pure virtual function and may also own state, constructors, non-virtual functions, and implemented virtual functions. C++ has no interface keyword; an interface-like runtime contract is normally an abstract class containing only the required pure virtual operations plus a virtual destructor when deletion through the base is supported. C++20 concepts provide a separate compile-time contract for generic code without inheritance or runtime dispatch.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.