|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



PURE




As we have already seen in the previous topics , a virtual method may or may not be overridden in the derived lasses. It means, it is not necessary for a derived class to override a virtual method.

But there are times when a base class is not able to define anything meaningful for the virtual method in that case every derived class must provide its own definition of the that method.

A pure virtual method is a virtual method that you want to force derived classes to override. If a class has any unoverridden pure virtuals, it is an "abstract class" and you can't create objects of that type.

" pure virtual function " or " pure virtual task " declaration is supposed to represent the fact that the method has no implementation.

There are two major differences between a virtual and a pure virtual function, these are below:

There CAN'T be a definition of the pure virtual function in the base class.
There MUST be a definition of the pure virtual function in the derived class.



EXAMPLE:
class Base;
pure virtual task disp();
end class

program main
initial
begin
Base B;
B = new();
B.disp();
end
endprogram

RESULT

Error: pure virtual task disp(); must be overridden in derived class

Index
Introduction
Class
Object
This
Inheritance
Encapsulation
Polymorphism
Abstract Classes
Parameterised Class
Nested Classes
Constant
Static
Casting
Copy
Scope Resolution Operator
Null
External Declaration
Classes And Structures
Typedef Class
Pure
Other Oops Features
Misc

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer