Private member Function :-
Although it is normal practice to place all the data in a private section and all the function in public section .But some situation may require certain function to be hidden (like private data) fro outside calls.
So we can make a function private . this private function can't be call directly using . operator .
It can only be called by another function that is a member function of that class.
The array can be used as member variable in class .
Realted Post : CLass and Object in C++ -2
Related post : CLass and Object in C++ -1
- // Private member Function
- //array within class
- #include<iostream>
- using namespace std;
- class sum_array{
- private:
- int ar[5]; //array can be used as member variable
- void print_sum(void); //private member function
- public:
- void getdata(void);
- };
- void sum_array::getdata(){
- cout<<" Input 5 element to sum ";
- for(int i=0;i<5;i++){
- cin>>ar[i];
- }
- print_sum();
- }
- void sum_array::print_sum(){
- int sum=0;
- for(int i=0;i<5;i++){
- sum=sum+ar[i];
- }
- cout<<" Sum :- "<<sum;
- }
- main(){
- sum_array x;
- x.getdata();
- // x.print_sum() ->> you can't access this using . operator as private
- }
Output:
I would like to thnkx for the efforts you have put in writing this site.
ReplyDeleteI am hoping the same high-grade web site post from you in the upcoming also.
In fact your creative writing skills has inspired me to
get my own blog now. Actually the blogging is
spreading its wings rapidly. Your write up is a great example of it.
Feel free to visit my web page: book of ra free game online;
,
Good day! I just would like to offer you a big thumbs up
ReplyDeletefor your excellent info you have here on this post.
I am coming back to your blog for more soon.
my weblog self build home ()
Searching for actions the whole family can get pleasure from?
ReplyDeleteAlso visit my blog post: legal drugs (www.legaldrugsforsale.com)
I like the valuable info you provide in your articles.
ReplyDeleteIཿll bookmark your weblog and check again here regularly.
I am quite certain I will learn many new stuff right here!
Good luck for the next!
My webpage vitamins good for brain