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

KRPano, I am seeking an expert to create a 360 degree virtual tour in KRPan...

I am seeking an expert to create a 360 degree virtual tour in KRPano for use on PCs, tablets and smartphones. You will be given with panoramas in order to create an advanced KRPano

., what is polymorphism

what is polymorphism

Pascal, Binomial coefficients are the numeric factors of the products in a ...

Binomial coefficients are the numeric factors of the products in a power of a binomial such as (x + y)n. For example, (x + y)2 = x2 + 2 x y + y2 has the coefficients 1 2 1. Binomia

Binary search tree and graph, Important Note: No course works, which have b...

Important Note: No course works, which have been submitted via hard copies or emails, will be accepted a short essay below edited in a document (word, other) files with

C++, padovan string c++ program

padovan string c++ program

Vectors, A body which has three forces acting on it is in equilibrium. One ...

A body which has three forces acting on it is in equilibrium. One force is 3N to the North and the other is 4N to the west. What us the magnitude and direction of the third force?

Structures of flowchart, Ask Draw a flowchart that print all even numbers f...

Ask Draw a flowchart that print all even numbers from 2 until 10

Arrays, how to write the code for operation research

how to write the code for operation research

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