different types of castings

Answer Posted / mms zubeir

The above answers are correct. I would like to add some
details to those.

1. const_cast:- is used to cast away the constness of a
variable.

2. static_cast:- is used to cast between two types with the
available static information about the variable. It doesn't
know anything about the run time information. Additionally,
it knows the type and access previledges of the
variables/objects involved in the casting. For example, we
cannot cast a private base.

3. reinterpret_cast:- is used to cast between any pointer
types and the types need not be related. The developer
needs to take care of the correct types to be casted.

4. dynamic_cast:- is used to cast between polymorphic types
only. It allows downcasting and casting between siblings as
well. If the cast fails, it returns a 0/NULL instead of the
pointer to the resultant object incase of success.

Is This Answer Correct ?    6 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }

1971


Is this job good for future? can do this job post grduate student?

1680


How to improve object oriented design skills?

558


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1133


How do you define social class?

594






What is inheritance write a program to show use of inheritance?

603


Can bst contain duplicates?

660


What is protected in oop?

596


what is difference between class template and template class?

2149


What is solid in oops?

592


What is the benefit of oop?

561


write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

1777


What are oops methods?

558


What are the important components of cohesion?

546


Can we create object of abstract class?

567