answersLogoWhite

0


Best Answer

Dynamic checking is necessary when we need to explicitly determine the actual type of a derived class of object knowing only its base class. Normally it is not necessary to know the actual type of a derived class as we can make use of the virtual interface provided by the base class. However, derived objects may (and often do) provide interfaces that are not accessible through the virtual call mechanism and, in order to invoke those specific interfaces, we need to know the actual type -- even if only to determine if those interfaces exist.

Note that the base class virtual interface should be viewed as being the common interface for all derived objects. Interfaces that are not common to all derived objects should ideally be placed in those specific derived classes to which they apply (or to a common derived class). But in order to access these interfaces we need to know if those interfaces really exist or not and we can only achieve that with dynamic checking.

The virtual call mechanism is itself a form of dynamic checking and, because it is generally the most efficient form, it is tempting to use it for all dynamic testing. However we must resist this because base class interfaces that are not common to all derivatives of that class results in code that is more difficult to maintain, is confusing to users of those interfaces and increases code size unnecessarily.

To use a real-world example, a bat is a mammal that can fly, but not all mammals can fly. Thus it would be inappropriate for the mammal class to provide a "fly" interface because that interface only applies to a specific class of mammals; those mammals that can fly. But if we have a container full of mammals and wish to separate those that can fly from those that cannot, we need to know which have the fly interface, and we can only do that by dynamically testing each mammal to determine its actual type.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When is dynamic checking necessary in c plus plus programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the two major types of programming languages in c plus plus?

Object oriented programming and structured programming.


When was Plus - programming language - created?

Plus - programming language - was created in 1976.


Is c plus plus a modular programming?

No, but it does support modular programming through namespaces.


Why study c plus plus programming?

we are using c plus plus programming for developing object oriented programing software.


Is C plus plus good for Embedded programming or not?

C and C++ programming is good for embedded programming. However, embedded implies long running, and that means the possibility of memory fragmentation. You will need to spend time working out or acquiring a method of memory management, such as the use of Smart Pointers and Garbage Collection. This is not a trivial task, but it is a necessary task.


What is the purpose of C plus plus?

Computer programming.


What is c plus plus primarily used for?

Programming.


Static vs dynamic binding in c plus plus?

Static binding occurs at compile time. Dynamic binding occurs at runtime.


What actually mean by object oriented programming Is C plus plus is a object oriented programming?

Just eat a watermellon!


Is NET programming is update from C plus plus programming?

No. .NET programming is Microsoft-specific, similar to Java in some respects, but it is non-portable. C++ is a general purpose and cross-platform programming language.


What is the use of c plus plus in banks?

Programming language.


What is the best website for C plus plus programming?

www.cplusplus.com