Why does the compiler ignore the definition of a method in a class in which it is declared as PURE?

 

This code compiles without any errors or warnings:

class CBase
  {
private:
   virtual void pureMethod() = 0;
  };

void CBase::pureMethod(void)
  {
   Alert(__FUNCTION__);
  }

Is it normal for the compiler to ignore method definition? This is deliberately incorrect code that contradicts itself.

Although I probably want too much feedback from the compiler😄

 

Hmm, is this really supposed to work?😄

class CBase
  {
public:
   virtual void pureMethod() = 0;
  };

void CBase::pureMethod(void)
  {
   Alert(__FUNCTION__);
  }

class CChild : public CBase
  {
public:
   void pureMethod() override
     {
      CBase::pureMethod();
     }
  };

void OnStart()
  {
   CChild child;
   child.pureMethod();
  }


 
Vladislav Boyko:

This code compiles without any errors or warnings:

Is it normal for the compiler to ignore method definition? This is deliberately incorrect code that contradicts itself.

Although I probably want too much feedback from the compiler😄

Of course, why not ?

A pure virtual method means the class is abstract and can't be instantiated.

And that the subclass must implement this method (or it will be abstract too). It says nothing about a default implementation.

 
Alain Verleyen #:

Of course, why not ?

A pure virtual method means the class is abstract and can't be instantiated.

And that the subclass must implement this method (or it will be abstract too). It says nothing about a default implementation.

I got it, thank you very much!