answersLogoWhite

0


Best Answer

Abstraction generally refers to abstract classes. An abstract class is one that cannot itself be instantiated, but can be derived from. Abstract classes are conceptual classes rather than concrete classes, and are intended to provide a common interface to the concrete classes derived from them. A class becomes abstract when it contains one or more pure-virtual methods, which must be implemented in the derived classes otherwise they become abstract classes themselves. A concrete class is one that provides a complete implementation for is abstract base classes, or inherits implementations from base classes other than those that originally declared the function to be pure-virtual.

An example of an abstract class is Shape. All shapes can be drawn, therefore Shape will have a Draw() method. However, it cannot implement this method unless it knows what type of shape it actually is. Therefore the Draw() method should be declared pure-virtual, thus rendering the Shape class to be abstract. You can then derive concrete shapes from the Shape class, such as Circle and Square classes, which will each provide the actual implementation for the Draw() method. Since Square and Circle are types of Shape, you can create collections of Shape objects and call their Draw() methods without regard to their actual type. If the object is really a Square, then calling Shape.Draw() will actually invoke Square.Draw(). There is no need to determine the actual type of the shape because every shape has a common interface.

This is really no different to overriding virtual methods in non-abstract classes. The main difference is that one would not be expected to instantiate a Shape (because it is abstract), other than through derivation, and the pure-virtual methods MUST be implemented by the derived classes, whereas normal virtual methods are simply expected to be overridden but it is not a requirement to do so unless you require an enhancement to the base class method.

Abstract classes typically have few if any member variables and little or no implementation. Ultimately, the class exists purely to provide a common interface to all its derivatives, and only functionality and member variables that are common to all its derivatives should be placed within it. Even if the abstract class provides a complete implementation for all its pure-virtual methods, you cannot instantiate an abstract class -- it must be derived from -- and all pure-virtual methods must still be implemented in the derivatives, even if only to call the base class methods explicitly.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the abstract feature in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the abstract datatypes in c plus plus?

Class Object Message


Why does VisualStudio c plus plus not have an option to give functions It is in VS c Sharp?

Turn on the intellisense feature.


What is feature that supported in c c plus plus and java but not in net?

C, C++ and Java are cross-platform languages. NET is for Windows-only.


Which is not a feature of abstract expressionism?

large scale painting


Defference between c plus plus and c?

these are difference in between c and c++: a) C is a SPL and C++ is a OOP. b) C has not concept of object but C++ has this feature. c) C has not 'class' name data type but C++ has.


What is the general structure of a C plus plus Language?

The central feature of any C++ program is classes which can be used to express ideas directly in code.


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 there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.


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.


How do C and C plus plus differ in terms of data abstraction and classes and structs?

They differ insofar as C does not use object-oriented programming at all -- there are no classes (only structures), therefore there was nothing to abstract. C++ (which literally means 'the successor to C') is an extension of C that primarily adds object-orientated support to the language. Everything you can do in C you can also do in C++, but with the added benefits of OOP you can do a whole lot more, more easily, including the creation of abstract data types.


How do you go full screen in c plus plus?

Going full screen is not a C or C++ feature; it is an operating system feature. If you are running under MS Windows, you can go full screen in a console application by using <Alt><Enter>. Use <Alt><Enter> again to go back to windowed mode. You can also preset this in the shortcut.


Which on of these is a feature of the international gothic style?

Reliance on abstract figures