What is the difference between virtual function instances in C ++?

What is the difference between the next two ads?

virtual void calculateBase() = 0;  
virtual void calculateBase();

I read the first (= 0) - "pure abstract function", but what does the second do?

+1
source share
8 answers

The first is called a pure virtual function. Normally, pure virtual functions have no implementation, and you cannot instantiate a class containing a pure virtual function.

The second is a virtual function (that is, a "normal" virtual function). A class provides an implementation for this function, but its derived class can override this implementation by providing its own implementation for this method.

+7

- " " - , , . , , . , .
, :

  • " " , , ,
  • "interface", ++ . , , ++.

- . , - . - , , .

+8

, .

.

+4

, .

Java, ?

+3

, ...

virtual void x() = 0;

- . . , ++ , , .

virtual void x();

- , , , .

+1

virtual void calculateBase() = 0;

- Pure, Interface. . .

void calculateBase();

, ( ) . .

+1

, ( "= 0" ), .

, ,

0

Java

virtual void calculateBase() = 0;  

abstract void calculateBase();

virtual void calculateBase();

void calculateBase();

,

void calculateBase();

++, " ",

final void calculateBase();

Java. final "default" ++. . .

0

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


All Articles