Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How many types of casting are there in C++?
When is a dynamic cast,static_cast,reinterpret cast used?

Answer Posted / shakti singh khinchi

There are 4 types of castings in C++ which is known as RTTI
(Run Time Type Identification).
Dynamic cast: When dynamic_cast cannot cast a pointer
because it is not a complete object of the required class
-as in the second conversion in the previous example- it
returns a null pointer to indicate the failure. If
dynamic_cast is used to convert to a reference type and the
conversion is not possible, an exception of type bad_cast is
thrown instead.

dynamic_cast can also cast null pointers even between
pointers to unrelated classes, and can also cast pointers of
any type to void pointers (void*).

static cast:static_cast can perform conversions between
pointers to related classes, not only from the derived class
to its base, but also from a base class to its derived. This
ensures that at least the classes are compatible if the
proper object is converted, but no safety check is performed
during runtime to check if the object being converted is in
fact a full object of the destination type.

const cast:This type of casting manipulates the constness of
an object, either to be set or to be removed

reinterpret cast;reinterpret_cast converts any pointer type
to any other pointer type, even of unrelated classes. The
operation result is a simple binary copy of the value from
one pointer to the other. All pointer conversions are
allowed: neither the content pointed nor the pointer type
itself is checked.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you implement a substr() function that extracts a sub string from a given string?

1004


Define token in c++.

1097


If a function doesn’t return a value, how do you declare the function?

1019


What is a storage class?

1201


What are proxy objects in c++?

1138


What is meant by iomanip in c++?

1144


What is a buffer c++?

1003


When is the destructor called?

990


What is an orthogonal base class in c++?

1112


Name the debugging methods that are used to solve problems?

1047


If there are two catch statements, one for base and one for derived, which should come first?

1001


What is the use of map in c++?

1110


What is a float in c++?

942


What is oop in c++?

1044


How can I disable the "echo" feature?

1110