answersLogoWhite

0

What is program written in c plus plus for RTTI?

Updated: 8/17/2019
User Avatar

Wiki User

9y ago

Best Answer

RTTI (run-time type information) is often necessary when dealing with a hierarchy of classes for which the virtual interface does not provide enough information about the total object from the base class alone.

The chief method of enabling RTTI is to use the dynamic_cast operator. This operator can cast pointers or references to base classes to pointers or references to derived classes. When casting to a pointer, a nullptr indicates the cast failed. When casting to a reference, a bad_cast exception is thrown (because references cannot be null). Thus before dynamically casting a reference, it pays to get some more information about the total object. This is achieved with the typeid operator.

void foo (shape& s)

{

if (typeid (s) == typeid (circle))

{

circle c = dynamic_cast<circle&> (s);

// operate upon c...

}

}

Note that RTTI is often misused. If it is impossible or undesirable to modify the base class to provide a suitable interface, then RTTI may be warranted. However, keep in mind that the problem is not that you are attempting to gain access to an interface that isn't available in the base class, it is that you are attempting to access that interface through the wrong class in the first place. Sometimes that is unavoidable, especially in user-interfaces where the application and system interact through widgets and controls where information can often become lost in the exchange. However, always try and look at alternatives whenever possible before resorting to RTTI as this can often indicate a poor design choice.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is program written in c plus plus for RTTI?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you rewrite a cuda file in c c plus plus language?

Yes, you can rewrite a cuda program originally written in c in c plus plus.


What is algorithms in c or c plus plus?

it is a step by step program written in simple English for our understanding


What is a C plus plus game project program?

A C++ game project program could either be a game written in C++ or a C++ library that helps you develop a game.


What has the author Jeri R Hanly written?

Jeri R. Hanly has written: 'Essential C[plus plus]for engineers and scientists' -- subject(s): C (Computer program language) 'Essential C++ for engineers and scientists' -- subject(s): C++ (Computer program language), C (computer program language)


What has the author Anthony Porter written?

Anthony Porter has written: 'The best C/C++ tips ever' -- subject(s): C++ (Computer program language), C (Computer program language) 'C++ Programming for Windows' 'C[plus plus] programming for Windows' -- subject(s): C


What has the author Eric P Bloom written?

Eric P. Bloom has written: 'The Turbo C++ trilogy' -- subject(s): C (Computer program language), C++ (Computer program language), Turbo C (Computer file), Turbo C++ 'Turbo C Plus Plus Trilogy' 'The C trilogy' -- subject(s): C (Computer program language)


Can you program games with c plus plus?

Yes, you can program games with C++.


What has the author Stephen C Dewhurst written?

Stephen C. Dewhurst has written: 'Programming in C[plus plus]' -- subject(s): C++ (Computer program language), C 'C++ common knowledge' -- subject(s): C++ (Computer program language) 'Programmer en C++' -- subject(s): C (Langage de programmation)


Does Adobe Flash use c plus plus scripting?

No, it does not. While the program itself was written in C++, Flash does not support C++. Any code inside your Flash project must be written in Actionscript.


What has the author David Vandevoorde written?

David Vandevoorde has written: 'C [plus plus] templates' -- subject(s): C 'C++ templates' -- subject(s): C++ (Computer program language), Microsoft Visual C++, Standard template library


Write a program in c plus plus to implement macro processor?

Don't write, it is already written, google for 'cpp'.


How to restart c plus plus program?

Exit the program and relaunch it.