M
M
Max Suprunenko2015-12-09 20:04:11
C++ / C#
Max Suprunenko, 2015-12-09 20:04:11

What's the difference between an interface in C# and pure virtual functions in C++ classes?

Recently switched from plus to sharp. I want to understand the difference between interface in C# and pure virtual classes in C++. Or is it basically the same thing?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
MiiNiPaa, 2015-12-09
@msuprunenko

" Purely virtual " are functions, not classes. A class that has at least one pure virtual function is called abstract . Sometimes " purely abstract " is a class that has only pure virtual functions + a virtual destructor. Such a class can indeed be used as an interface, and is designed to work like interfaces in other languages. The differences are minimal, if any.

S
Stanislav Makarov, 2015-12-09
@Nipheris

Same thing, pure abstract classes in C++ are a way to get functionality similar to the concept of "interface" in those languages ​​where it exists (C#, Java, etc.).
Thanks to multiple inheritance in C++, base classes can include both classes with real behavior (i.e., with implementations of some methods) and "interface" classes, i.e. classes with only pure-virtual member functions.

S
svd71, 2015-12-09
@svd71

Alas, the Achilles heel of OOP is inheritance. You cannot inherit from more than one class. It doesn't matter if you inherit a real class or an abstract one. But with the help of interfaces, it is possible to bypass this limitation and still build the desired object with the necessary properties, and with a bunch of interfaces, and not just one.

O
OnYourLips, 2015-12-09
@OnYourLips

An interface is a convention for working with an object.
What

pure virtual classes in C++
I didn't understand.

S
Sergey, 2015-12-09
Protko @Fesor

None, it's just that there is more code in the version with virtual classes . But in fact the profit is the same, classes can inherit (implement) several interfaces (virtual classes) at once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question