Virtual function is abstract

Virtual function is abstract

We are getting an error message that says a function fromwithin a class C cannot allocate instanceof type C because one of the virtual functions(the one we wrote) is abstract. How can we make it non-abstract?

Before changing an abstract class to a concrete class, you first must understand why the creator of that class made it abstract in the first place. In general, this is a decision that is made during the object-oriented design process. When we speak of abstract in object-oriented terms, it more or less means the same thing as it does in philosophical terms. Something abstract is conceptual; thereforeit is intangible and can be realized only when applied to some thing tangible or concrete.

A classic example of an abstract class is Shape. The Shape may contain member functions to draw a circle, square or triangle, but it means nothing unless it can be applied to something tangible; therefore, the C++ compiler will prohibit any instatiation of objects of type Shape. In order to use the Shape class, you must derive a new class from it that implements the member functions (or methods) defined in the abstract class, thus making the derived class concrete. For example, you may derive a Table, House, and Boat class from the Shape abstract class. Provided you implement the functions in the base class that make it abstract, all your derived classes will be concrete classes. Then, you will be able to instantiate objects of those types. Hence you can have a square table, house, or boat.

Finally, what makes a class abstract in C++ is that at least one member function is declared as pure virtual. Pure virtual functions are virtual functions that are initialized to zero, and contain no implementation. Below is a code example:

// Abstract base class Shape//class Shape{// pure virtual functionspublic:	virtual void Round( ) =3D 0;	virtual void Square( ) =3D 0;	virtual void Triangle( ) =3D 0;};
To use an abstract class, you must derive a new class from it, and override all pure virtual functions by providing implementation. See code extract below:
// Concrete class Table inherits from abstract class shape//class Table : public Shape{// Functions implemented from abstract class shape.  Implementation for these functions will usually be// located in a methods file (.cpp file extension).public	void Round( );	void Square( );	void Triangle( );};

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes