What does function assignment do? By virtual function

I need to understand these statements:

virtual string FOOy() = 0; virtual string FOOx( bool FOOBAR ) = 0; 

I'm not sure if a function that is virtual has anything to do with it ...

+4
source share
6 answers

Although your test file is extremely incomplete, because of the virtual it looks as if it is inside a class definition.

In this context, = 0 not an assignment at all, but is part of a confusing syntax that states that the function of a virtual member is "pure". A pure virtual member function may have an implementation (defined elsewhere), but one is optional, and the function itself prohibits instantiating the class.

That is, a class with pure virtual member functions can be called "abstract".

A peer-reviewed peer-reviewed C ++ book describes this topic in more detail.

+7
source

This means that the method is pure or abstract. This means that the method must be declared by extending classes (thanks for this clarification - see comments below).

+2
source

Syntax = 0 is how you declare a pure virtual function in C ++. A pure virtual object has no implementation in the class declaring it - any subclass must implement this function in order to be realistic.

http://www2.research.att.com/~bs/glossary.html#Gpure-virtual-function

+2
source

This makes the function a pure virtual function . This means that the class declaring the function is abstract, and subclasses must provide an implementation for this function.

+2
source

By adding = 0 , you declare the virtual function as a pure virtual function. This means that derived classes must implement the method before they can be created. Usually the base class has no implementation.

This is also called an abstract function in other languages ​​such as Java and C #.

+2
source

It just means that the developer (original writer) of the class in which FOOx and FOOy assumed that it would be used as interfaces to its derived classes.

And these virtual mean that the derived class 'implementation will be implemented using the base class ' pointer. Thus, its use as an interface becomes possible by declaring them as virtual .

And finally, answering your question. The value-assignment, in particular, the assignment of 0 function means, explicitly speaking, that the function has no definition. (Although you can specify a definition for it, it must be called explicitly by derived classes)

0
source

Source: https://habr.com/ru/post/1395704/


All Articles