google.com, pub-7659628848972808, DIRECT, f08c47fec0942fa0 Pro Learner: Cpp methods

Please click on ads

Please click on ads

Sunday 31 January 2021

Cpp methods

 So the methods are functions that belongs to the class. 


There are two ways to define a function that belongs to a class. 

1.inside class definition

2.outside class definition

Note-methods ko usi tarah se access krte hai jis tarah attributes ko ko kiya jata hai. Iske liye class ka ek obj create krte hai or obj create create krne ke baad (.) Lagakar method ka naam likh kr usse call kiya jata hai. 

Ex-

class s{

public:

void method() {

cout<<"hello guys ";

}

};

int main() {

s p;

p. method;

return 0;

}

That is the example of inside the class method. 

Ex-

class s{


public:


void method() ;

};

class s::method() {

cout<<"hello guys ";

}





int main() {


s p;


p. method;


return 0;


}

That is the example of outside the class method. 

Thanks for watching.. 👀🎥

No comments:

Post a Comment