Can I know the usefulness of the ‘this’ pointer?
Whenever an object of a class is created, a pointer to the current object is held by the ‘this’ pointer. The this pointer exists for all non-static members of a class- the static members do not have a ‘this’ pointer associated with them. Each object maintains its own set of data members, but all objects of a class share a single set of methods.A single copy of each method exists within the machine code that is the output of compilation and linking. The compiler uses the "this" pointer to internally reference the data members of a particular object. So if there are more than one object of a class type within an application, we need to be able to interact with the right object’s members- compiler inserts implicitly code that calls a object reference with the this pointer.
class Vehicle
{
Int Registration = 0;
public:
Vehicle(){}
Virtual void GetRegistration() = 0;
Void SetRegistration(int);
};
Void SetRegistration(int regis)
{
this->Registration = regis;
}
C++ FAQ Home
Sponsored links
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Software Localization Tool Sisulizer
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
Localize DotNet, C++ Builder, Delphi, C/C++, Visual Basic & Java apps & html help. Try Sisulizer now
CSTSOFT Instrumentation .NET & ActiveX Components
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
A collection of 13 instrumentation .NET/ActiveX/VCL components including Gauge,Knob,LED,Trend etc.
Web based bug tracking - AdminiTrack.com
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
AdminiTrack offers an effective web-based bug tracking system designed for professional software development teams.
