How to acces private member function in C++/CPP
Program to show accessibility of private member function.
//private member function(skeleton) can be accessed using
//member function only and not by object and dot operator
#include<iostream>
using namespace std;
class item
{
private:
int number;
float price;
void getdata(int a, float b) // here member function getdata
//is private so not accessible by object
{
number=a;
price=b;
}
public:
void showdata()
{
cout<<"Number="<<number<<" \nPrice="<<price<<endl;
}
void putdata()
{
getdata(10, 100.4); // private member function getdata
// is called from within another m.f.
}
};
int main()
{
item x;
//x.getdata(10, 10.5); // private mf can not be accessed using object
x.putdata();// private mf can be accessed using another mf only
x.showdata();
return 0;
}
Program to show accessibility of private member function.
//private member function(skeleton) can be accessed using
//member function only and not by object and dot operator
#include<iostream>
using namespace std;
class item
{
private:
int number;
float price;
void getdata(int a, float b) // here member function getdata
//is private so not accessible by object
{
number=a;
price=b;
}
public:
void showdata()
{
cout<<"Number="<<number<<" \nPrice="<<price<<endl;
}
void putdata()
{
getdata(10, 100.4); // private member function getdata
// is called from within another m.f.
}
};
int main()
{
item x;
//x.getdata(10, 10.5); // private mf can not be accessed using object
x.putdata();// private mf can be accessed using another mf only
x.showdata();
return 0;
}
Skeleton in C++
ReplyDeleteHow to acces private member function in C++/CPP
Program to show accessibility of private member function.
Skeleton in C++
How to acces private member function in C++/CPP
Program to show accessibility of private member function.