OOPS: how to enforce that a function is implemented in derived class

I have a function (say, func_x) in base class.
This function is called within base class by another function (say func_y).

How can I enforce that in derived class, func_x is overridden?

In reply to verif_learner:

This is known as an abstract class with pure virtual methods

virtual class base;
  pure virtual function void func_x;
  virtual function void func_y;
    func_x;
  endfunction
endclass

class base cannot be constructed directly; it must be extended with an implementation of func_x.

In reply to dave_59:

In reply to verif_learner:
This is known as an abstract class with pure virtual methods

virtual class base;
pure virtual function void func_x;
virtual function void func_y;
func_x;
endfunction
endclass

class base cannot be constructed directly; it must be extended with an implementation of func_x.

Dave,
I assume pure virtual method is sufficient to enforce that derived class implements such a method. I don’t think the class needs to be virtual.
I assume a non virtual class with a pure virtual method can be instantiated …

In reply to verif_learner:

A class with a pure virtual method needs to be marked as virtual since you cannot be allowed to construct a class with a pure virtual method.

In reply to dave_59:

In reply to verif_learner:
A class with a pure virtual method needs to be marked as virtual since you cannot be allowed to construct a class with a pure virtual method.

So, what is the point of marking a class virtual, when it has a pure virtual function?
Is it just for readability?

Is the following understanding correct?

  1. a virtual class can have non virtual functions. this class cannot be instantiated
    But one can simply derive from this class and instantiate the derived class without any issues
  2. a class with pure virtual function has to be declared as virtual as well
    In this case, the derived class has to override the pure virtual functions and implement them, without which the derived class becomes virtual as well
  3. so, effectively, one can have hierarchy of virtual classes, each progressively implementing pure virtual functions

In reply to verif_learner:

You might say it’s for readability or safety. You are showing the intent of the base class is only useful if you extend from it.