19 This pointer in C++ zoom | C++ Programming Tutorial for beginners | cpp | C plus plus

Опубликовано: 24 Февраль 2021
на канале: tech fort
23
3

#this pointer in C ++ :
- Every object in C++ has access to its own address through an concept called this pointer.

this is pointer is an implicit parameter to all the member functions.

so inside member function "this" is used to refer to invoking the current class object.

Note: friend function dont have access to this pointer
bcoz friends functions are not a member functions of a class. so only member function can access this pointer.

Example:
using namespace std;
class College{

string name;
string loc;
public :
int dte;
College(int d=0,string n="NoName",string l="NoLocation"){
dte=d;
name=n;
loc=l;
}
int getDte(){
//this - dte;
return dte;
}
string getname(){
//this - name;
return name;
}
string getloca(){
return loc;
}
void show(){