Tutorial by Examples

All non-static member functions have a hidden parameter, a pointer to an instance of the class, named this; this parameter is silently inserted at the beginning of the parameter list, and handled entirely by the compiler. When a member of the class is accessed inside a member function, it is silent...
In this context, using the this pointer isn't entirely necessary, but it will make your code clearer to the reader, by indicating that a given function or variable is a member of the class. An example in this situation: // Example for this pointer #include <iostream> #include <string>...
This is an actual useful strategy to differentiate member data from parameters... Lets take this example : // Dog Class Example #include <iostream> #include <string> using std::cout; using std::endl; /* * @class Dog * @member name * Dog's name * @function bark * ...
this can also be cv-qualified, the same as any other pointer. However, due to the this parameter not being listed in the parameter list, special syntax is required for this; the cv-qualifiers are listed after the parameter list, but before the function's body. struct ThisCVQ { void no_qualifi...
C++11 Similarly to this cv-qualifiers, we can also apply ref-qualifiers to *this. Ref-qualifiers are used to choose between normal and rvalue reference semantics, allowing the compiler to use either copy or move semantics depending on which are more appropriate, and are applied to *this instead of...

Page 1 of 1