0% found this document useful (0 votes)
49 views

Pure Virtual Function

A pure virtual function is defined with the "= 0" syntax and has no implementation in the class that declares it. This allows a class to define an interface for derived classes to implement by overriding the pure virtual functions. Abstract base classes contain at least one pure virtual function and are used to define an interface for subclasses without needing to instantiate the base class itself. Pure virtual functions make code simpler by allowing access to derived class members through a base class pointer.

Uploaded by

Enrico Freefire
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Pure Virtual Function

A pure virtual function is defined with the "= 0" syntax and has no implementation in the class that declares it. This allows a class to define an interface for derived classes to implement by overriding the pure virtual functions. Abstract base classes contain at least one pure virtual function and are used to define an interface for subclasses without needing to instantiate the base class itself. Pure virtual functions make code simpler by allowing access to derived class members through a base class pointer.

Uploaded by

Enrico Freefire
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pure virtual function

A virtual function which has no definition (i.e. body) is known as pure virtual function. They start with virtual
keyword and end with equal to zero. We cannot change the signature of pure virtual function.

Syntax,

Virtual return type function name () =0; // pure virtual function

Example:

Class base

Public:

Virtual void show () =0; // pure virtual function


};

Class derived: public base

Public:

Void show ()

…….}

};

Abstract base class


A class that has at least one pure virtual function (i.e., a function that has no definition).Abstract classes
are used to provide an interface for its derived classes.
Q. Why do we use pure virtual function?
->To make the code simpler
->To access the members of derived class through the pointer of base class.

You might also like