Nptel Docs Week-7
Nptel Docs Week-7
WEEK-7
TYPE CASTING – PART 1
3. double result = i / d;
4. Conversions:
Upcast – okay!
Downcast – No! error!
A* to void* - okay! But lose of data!
Void* to A* - No! Error!
7.
- For the last example, it will not give any error in c-style
casting…which is very dangerous.
1. Built in types
- Solution:
Window::onresize()
- a = static_cast<A>(b);
why this is an error in case of unrelated class?
- Solution:
-To provide a constructor in A class of B type.
5. Static cast pitfall:3 (Unrelated class)
1. typeid operator:
When typeid is used with polymorphic objects (i.e., objects of a class with at least one
virtual function), typeid will return the dynamic type of the object, meaning the type of the
actual object that the pointer or reference points to.
If the object is not polymorphic, typeid will return the type of the expression, which
could be the base class.
MULTUPLE INHERITANCE:
1. constructors and destructors
2. Object lifetime (program)
3. Diamond problem: