Session-13 - This pointer Dynamic memory allocation...

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

This pointer, Dynamic memory allocation, Constructors and Destructor
Image of page 1

Subscribe to view the full document.

Scope Resolution Operator New operator in C++ Has many roles To define member functions outside classes Initialization of static data members To access a global variable with same name as that of local variable
Image of page 2
Image of page 3

Subscribe to view the full document.

this pointer ‘this’ pointer is passed as a hidden argument to all non-static member function calls and is available as a local variable within the body of all non-static functions constant pointer that holds the memory address of the current object Not available in static member functions as static member functions can be called without any object (with class name). ‘this’ is a keyword in C++
Image of page 4
this pointer - uses When local variable’s name inside a member function is same as a data member’s name, the data member is hidden inside the member function (the name conflicting local variable hides the data member with the same name) -> this pointer is used to access the hidden data member can get the address of the invoking object can return the invoking object Can perform cascaded member function calls(chained member function calls)
Image of page 5

Subscribe to view the full document.

Image of page 6
Image of page 7

Subscribe to view the full document.

new and delete in C++ Similar to malloc and free in C
Image of page 8
Image of page 9
  • Fall '16
  • M.R.DUBE
  • Method, Garbage collection, copy constructors

{[ snackBarMessage ]}

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