answersLogoWhite

0


Best Answer

An abstract class is a class that has a pure virtual function.

A pure virtual function can be used in a base class if the function that is virtualised contains parameters that can and should be interchangeable, but the function should remain intact.

For example, there is a base class Object in a game that will contain movement for simple objects, but the movement function may need to use different parameters per object.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

An abstract class is an abstract data type (ADT). They are used to describe a common interface to the objects that derive from them. You cannot instantiate objects from abstract classes, they must be derived from. Only derivatives that fully implement all the virtual methods they inherit from their ADTs can actually be instantiated

A virtual class is used in multiple inheritance cases where a derived class inherits from two or more base classes that each inherit from a common base class. The common base class must be declared virtual in all its derivatives to ensure only one instance of the common base class is present in any classes that inherit from two or more of the derived classes. Without virtual inheritance, the most-derived class would have multiple instances of the common base class, which introduces an undesirable ambiguity to the class.

For instance, if you declare an animal ADT from which winged_animal and mammal are both derived, a bat class would inherit two animal ADTs as it is both a mammal and a winged_animal. To avoid this, animal needs to be declared a virtual inherited class in both mammal and winged_animal. Now bat will inherit only one animal ADT and the ambiguity is completely removed.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Unless you want to go on to teach Computer Science, much of anything beyond the fundamentals in C++ doesn't have a direct application.

That being said, it's worth learning as much as you can. In the real world, being able to quickly come up with a elegant solutions to complex problems is a very valuable skill. Exercising your mind with programming courses will help you develop that ability.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the applications of An Abstract Class in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write abstract class in c plus plus?

An abstract class is any class definition that contains at least one pure-virtual function. class AbstractClass { public: virtual void DoSomething()=0; // Pure-virtual. };


Is an abstract class virtual by default?

Unlike abstract class in C++, the abstract class in C# does not have any methods defined as virtual by default. The concept of virtual are not the same between C# and C++, either. Any virtual method must be defined explicitly in C#. Related to abstract methods - interestingly, an abstract class in C# does not have to have any abstract methods. However, the reverse, if a class need to have at least one abstract method, that class must be defined as abstract.


Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.


What is abrstac class and virctul function in c?

I have to assume the question is for C#, not C, because C does not provide abstract class concept.public abstract class A1 { public virtual void SayHi() { Console.WriteLine("Hello World"); }public abstract void DoSomething();}The above abstract class A1 contains 1 virtual method and 1 abstract method. [Note that because of the abstract keyword for Dosomething(), A1 must be declared as abstract. An abstract class DOES NOT have to have any abstract methods!!)The virtual function SayHi() provides a implementation, while the abstract function provides nothing but only the method signature( the name of the method, the return type, and method parameters and their data types). The derived class of A1 has the option to override SayHi() and must implement (or defer to subclasses of this derived class) the method DoSomething()


Is reader class is an abstract class?

For Java: Yes, Reader is an abstract class in package of java.io; For C#: No, Reader is NOT one of the defined library classes. Of course you create one.

Related questions

What are the abstract datatypes in c plus plus?

Class Object Message


Write abstract class in c plus plus?

An abstract class is any class definition that contains at least one pure-virtual function. class AbstractClass { public: virtual void DoSomething()=0; // Pure-virtual. };


Is an abstract class virtual by default?

Unlike abstract class in C++, the abstract class in C# does not have any methods defined as virtual by default. The concept of virtual are not the same between C# and C++, either. Any virtual method must be defined explicitly in C#. Related to abstract methods - interestingly, an abstract class in C# does not have to have any abstract methods. However, the reverse, if a class need to have at least one abstract method, that class must be defined as abstract.


When you define a c plus plus class what items are considered part of the interface?

The interface of a C++ class is the public methods and attributes that are exposed by the class. In a pure abstract base class, the interface is enforced by the compiler in each of the derived child classes.


Is an abstract class cannot have any member variable in C plus plus?

An abstract base class may have member variables. Whether or not it actually needs member variables depends on the nature of the base class itself. If the variable is common to all derived classes, then it makes sense to place the variable in the base class. If some derived classes have no need of the variable, then it is better to derive an intermediate class with the variable, and to derive those classes that require that variable from the intermediate class, rather than directly from the abstract class.


Can a c plus plus class be derived from a Java class?

No.


What is abrstac class and virctul function in c?

I have to assume the question is for C#, not C, because C does not provide abstract class concept.public abstract class A1 { public virtual void SayHi() { Console.WriteLine("Hello World"); }public abstract void DoSomething();}The above abstract class A1 contains 1 virtual method and 1 abstract method. [Note that because of the abstract keyword for Dosomething(), A1 must be declared as abstract. An abstract class DOES NOT have to have any abstract methods!!)The virtual function SayHi() provides a implementation, while the abstract function provides nothing but only the method signature( the name of the method, the return type, and method parameters and their data types). The derived class of A1 has the option to override SayHi() and must implement (or defer to subclasses of this derived class) the method DoSomething()


Is reader class is an abstract class?

For Java: Yes, Reader is an abstract class in package of java.io; For C#: No, Reader is NOT one of the defined library classes. Of course you create one.


What is the role of object in c plus plus?

An object in C++ is an instance of a C++ class.


What is abrstac class and virctulfunction in c sharp?

abstract class is a class label with abstract. It is just like a common class, with the following characterics: 1. Abstract class cannot be instantiate with an instance. 2. Abstract class may have abstract methods, while the normal class cannot have abstract methods. a virtual function in C# is a way to provide a default implementation for the class hierarchy. Both abstract class and common class (not sealed) can have virtual methods/ functions. Note that an abstract method (of an abstract class) is defining the intent, no codes (no default behavior), the implementation are left for the derived classes to do so. The virtual function if defined in an abstract class must define the implementation, the minimum is to do nothing: public abstract class Vehicle { public abstract int GetNumberOfTires(); public virtual void Move() { // default is doing nothing} } public class Car : Vehicle { public override int GetNumberOfTires() { return 4; } public override void Move() { throws new OutOfFuelExpection(); } }


What is nested class in c plus plus?

s.


What is the unit of programming in c plus plus A. Function B. class C. object D. Attribute?

B. Class.