Restriction on using Abstract Class Assignment Help

Assignment Help: >> Polymorphism - Restriction on using Abstract Class

Restrictions on Using Abstract Classes

An Abstract class cannot be used for:

  • Variables or member data
  • Argument types
  • Function return types
  • Types of explicit conversions

 

Other restriction of abstract class is that if the constructor for an abstract class calls a pure virtual function else directly or indirectly, the result is undefined. Although, constructors and destructors for abstract classes could call other member functions.

A Pure virtual function could be defined for abstract classes, but they could be called directly only through using the syntax:

abstract-class-name:: function-name( )

This should helps when designing class hierarchies whose base class(es) include pure virtual destructors, since base class destructors are always known in the process of destroyings an object. Let consider the given example:

#include <iostream.h>

// Declare an abstract base class with a pure virtual destructor.

class base

{

public:

base() {}

virtual ~base()=0;

};

// Provide a definition for destructor. base::~base()

{

}

class derived:public base

{

public:

derived() {}

~derived(){}

};

void main()

{

derived *pDerived = new derived;

delete pDerived;

}

Whenever the object pointed to through pDerived is deleted, a destructor for class derived is called and after that the destructor for class base is called. The null implementation for the pure virtual function ensures in which at least a few implementation exists for the function.

Remember Within the preceding instance, the pure virtual function base::~base is called implicitly from derived::~derived. That is also possible to call pure virtual functions explicitly using a fully qualified member-function name.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd