interface, base class, abstract class?

Hi, I was trying to learn exactly what an interface was, and the site I was on has confused me about something else, that I am hoping someone could please clarify for me. I have been learning about classes, and my book says the base class is the class which other classes will inherit from, and that base class can contain virtual functions, therefore the derived classes can use those virtual functions to make the function specific for themselves. But, this website says that, a class is made abstract by having a virtual function. So I then thought that maybe a base class and a abstract class were the same thing, however, it then says the abstract class cannot be used to instantiate objects which i believe base classes can be?

So my questions are, is a base class different from an abstract class?
if so, virtual functions exist in both?
Also if anyone could explain a interface in the simplest terms, other places I have looked have explained it in terms which i think is a bit advanced for me.

Thank you
Let me first confuse you with: https://www.aristeia.com/Papers/IEEE_Software_JulAug_2004_revised.htm

"Interface" is the link between two parties. The "GUI", graphical user interface is between human and program; it offers ways for human to use the program(s).

Interface of a class is between client/user/programmer and class; it defines how you can use the class (objects). For example, the std::vector has members size(), push_back() and operator[]. With those you know how many elements a vector has, you can add elements, and you can access elements.


A class is abstract if it has member functions that have no implementation. You can't create such object, because you could not use all its functions.

You can inherit abstract class and provide the missing implemenatations in the derived class. You can then create objects of the derived type. Since you inherit, the abstract class is used as base class.

A class that has virtual functions is not automatically abstract.


You can't create objects of type that is abstract. You have to inherit. All those derived classes have the "common interface" defined in the base. Therefore, all those derived classes can be used similarly.
a class is made abstract by having a virtual function
The missing word here is 'pure'. A class is abstract (and hence cannot be instantiated) when it has pure virtual functions. A pure virtual function ends with =0;. See:

http://www.trytoprogram.com/cplusplus-programming/abstract-class-pure-virtual-function/

So my questions are, is a base class different from an abstract class?
Yes. A base class isn't necessarily abstract but an abstract class can only serve as a base class.

if so, virtual functions exist in both?
Yes. At least the destructor, so that you can call delete for a base class pointer.

Also if anyone could explain a interface in the simplest terms, other places I have looked have explained it in terms which i think is a bit advanced for me.
The word 'interface' is sometimes used as a synonym for abstract classes (as far as I know the term isn't used in the C++ language specification). See:

https://www.tutorialspoint.com/cplusplus/cpp_interfaces.htm
Topic archived. No new replies allowed.