Describe the mechanism of accessing data member and member function inside the member function of same class
Answers
Answered by
0
the mechanism of accessing data members and member functions in the following cases is done by 1.Using object and dot membership operator.
2.accessing a local variable of a function. Example for how to access data members and member functions inside a member function of another class. #include<iostream.h> class a
{ public: int x; void display() { cout<<"sample \n"; x=111; } }; class b { public: void display() { a s; cout<<" Member function \n"; s.display(); cout<<" x = "<<example<<"\n"; } }; void main() { b b1; // b1 is a object of class b. b1.display(); }
2.accessing a local variable of a function. Example for how to access data members and member functions inside a member function of another class. #include<iostream.h> class a
{ public: int x; void display() { cout<<"sample \n"; x=111; } }; class b { public: void display() { a s; cout<<" Member function \n"; s.display(); cout<<" x = "<<example<<"\n"; } }; void main() { b b1; // b1 is a object of class b. b1.display(); }
Similar questions