Explain the special pointer this, C/C++ Programming

Assignment Help:

The Special Pointer 'this'

When various instances of a class come into existence, it naturally follows that each instance has its own copy of member variables. If this were not the case, then for obvious reasons it would be impossible to make more than one instance of the class. On the other hand, even though the class member functions are encapsulated with the data members inside the class definition, it would be very inefficient in terms of memory usage to duplicate all these member functions and store the code for them within each instance. thus, only one copy of each member function per class is stored in memory, and must be shared by all of the instances of the class.

But this poses a big problem for the compiler: How can any given member function of a class knows which instance it is supposed to be working on ? In other words, up to now in a class member function you have easily been referring to the members directly without regard to the fact that when the instantiations occur each data member will have a dissimilar memory address. In other words, all the compiler knows is the offset of each data member from the start of the class.

 


Related Discussions:- Explain the special pointer this

Program to implement a ftp client, Write a program in C to implement a FTP ...

Write a program in C to implement a FTP client that can interoperate with a default FTP server . The client should implement basic FTP commands GET PUT LIST DELE . GET -> to

Decode the Code, Smugglers are becoming very smart day by day. Now they hav...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Result system, write a promgram using object oriented peramid

write a promgram using object oriented peramid

Write a program that reads data from array, Write a program that reads data...

Write a program that reads data into an array of type int. You must use an array. The numbers input are attendance numbers at a conference. Keep a running average, number of events

Basic input -output library of subroutines, GetChar - get a character fro...

GetChar - get a character from the keyboard, echo to the display and return it in reg al. - Note: if a linefeed (LF) is received (Enter key), a carriage return (CR) will als

201 it, overloadstream insertion opertator to display the data of object on...

overloadstream insertion opertator to display the data of object on the console

Multiple constructor, Constructor public class ListNode {    //...

Constructor public class ListNode {    // package access members; List can access these directly private E data; // data for this node privateListNode nextNode; /

Program to print a series, Write a program called Series that will print/di...

Write a program called Series that will print/display a series of numbers starting with 1 and ending with the last number that is less than 30. The series should include only odd n

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd