Week 4.pptx - Object-Oriented Programming(OOP Week \u2013 04 Feb 10-14 2019 Instructor Basit Ali Email [email protected] Object-Oriented

Week 4.pptx - Object-Oriented Programming(OOP Week – 04...

This preview shows page 1 - 9 out of 31 pages.

Object-Oriented Programming (OOP) Week – 04 Feb 10-14, 2019 Instructor: Basit Ali Email: [email protected] Object-Oriented Programming (OOP)
Image of page 1
Type Casting Converting an expression of a given type into another type is known as type-casting
Image of page 2
Types of Type-Casting Implicit conversion Implicit conversions do not require any operator Perform by the compiler automatically Explicit conversion Perform by the programmer Data loss might occur
Image of page 3
Implicit Casting
Image of page 4
Implicit Casting Implicit conversions also include constructor or operator conversions, which affect classes that include specific constructors or operator functions to perform conversions For example Here, an implicit conversion happened between objects of class A and class B, because B has a constructor that takes an object of class A as parameter.
Image of page 5
Implicit Casting (Example)
Image of page 6
Explicit Casting User defined typecast for the result to make it to a particular data type In C++, it can be done by two ways: By Assignment Also known as forceful casting where type indicates the data type to which the final result is converted. By cast Operator A Cast operator is an unary operator which forces one data type to be converted into another data type.
Image of page 7
Explicit Casting Syntax: (type_name) expression/value Or Type_name (expression/value) Example: Float f = 15.65; int a; a= (int) f; Or a = int(f);
Image of page 8
Image of page 9

You've reached the end of your free preview.

Want to read all 31 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes