different types of castings
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sanjay makwana
Const Cast,
Static cast,
reinterprit cast,
dynamic cast
| Is This Answer Correct ? | 8 Yes | 7 No |
Answer / vinayaka kc
2 types of casting
1] Implicit casting
2] Explicit casting
(a)Const Cast,
(b)Static cast,
(c)reinterprit cast,
(d)dynamic cast;
| Is This Answer Correct ? | 5 Yes | 4 No |
What are oops functions?
Which is better struts or spring?
Why is static class not inherited?
Question In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Question Submitted By :: Sunil Kumar I also faced this Question!! Rank Answer Posted By Re: In a class, there is a reference or pointer of an object of another class embedded, and the memory is either allocated or assigned to the new object created for this class. In the constructor, parameters are passed to initialize the data members and the embedded object reference to get inialized. What measures or design change should be advised for proper destruction and avioding memory leaks, getting pointers dangling for the embedded object memory allocation? Please suggest. Answer # 1 use copy constructors 0 Shanthila There is something to be taken care in destructor, in copy constructor, suppose the memory is assigned to the embedded member object pointer with the parameter passed value, but if some other objects of different class also are pointing to this memory, then if some one deletes the object then this class member pointer object will become dangling, or if the object is not deleted properly then there will be memory leak. Please suggest the design change required to handle or avoid this situation
what is ns string? what is ns array?
What is the main difference between C++ and Java
What is a linked list?
WAP to generate 2n+1 lines of the following pattern on the computer screen:
What is a class?
32 Answers Infosys, TCS, Thylak,
What is the difference between procedural programming and oops?
Why u change company?
What is persistence in oop?