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

Loops, Create a program that will accept 3 numbers. The first number (num1)...

Create a program that will accept 3 numbers. The first number (num1) is the common difference and the second number (num2) is the starting number and the 3rd number (num3) is the m

Example program of c programming, Write a c program to determine interchang...

Write a c program to determine interchanged values between two variables?[Hint - if loop] What will be the output of the program? How many times this loop will execute? Wr

Minimum shelf, At a shop of marbles, packs of marbles are prepared. Packets...

At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with thes

Implement a binomial tree class, a) Implement a binomial tree class with a ...

a) Implement a binomial tree class with a method that calculates the value of an option passed in to the class. The binomial tree should not rely on specific features of the differ

Need squid web proxy with ffmpeg to convert flv to h.264, Need Squid Web Pr...

Need Squid Web Proxy with ffmpeg to convert flv to h.264 Project Description: We need a squid proxy setup with the modification that will transcode FLV to h.264 in real-time,

#minimum shelf, #At a shop of marbles, packs of marbles are prepared. Packe...

#At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with the

Explain function overloading, F u nction overloading: Functions can b...

F u nction overloading: Functions can be defined with same name.  Depending upon the type of argument passed the function will perform.  This is known function overloading

Palindrome, A palindrome is a string that reads the same from both the ends...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Create an array of strings, Create an array of Strings and fill it with som...

Create an array of Strings and fill it with some interesting text, such as vacation destinations, album names, or weapon names from a CRPG. Display three elements of the array on t

Program to draw a circle - c program, Program to draw a circle: int ma...

Program to draw a circle: int main(void) {    /* request auto detection */    int gdriver = DETECT, gmode, errorcode;    int midx, midy;    int radius = 100;

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