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?
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?
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.