What is the effect of overriding a (regular) virtual method with a pure virtual method?

Let's say that

class A {    
public:    
    virtual int foo() { cout << "foo!"; }    
}

class B : public A {
public:    
    virtual int foo() =0;
}

class C : public B {
public:
    virtual int foo() { cout << "moo!"; }
}

Is this really a redefinition? I think this is really an overload . What is the point of doing something similar, design wise?

We got the base class A. Then we got the abstract derived class B, which was obtained from the concrete class A, and then the implementation of B through C.

What are we doing here and does it make sense?

+3
source share
4 answers

Overloading means that you have two functions with the same name but with different parameters. This is not true.

Example:

int functionA() { /*...*/ };
int functionA(int someParameter) { /*...*/ };

. .

. :

, . , , , (= ). .

, foo(). , , , , ( foo()) . , .

+3

, , B .

+1

- , p A* C, p->foo() C::foo()

, , - , . , .

+1

, , B, int foo();. , - , , foo(), , - , , , A:: foo().

B , - , .

+1

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


All Articles