Download - Class Access Modifiers
Transcript
-
8/17/2019 Class Access Modifiers
1/3
// The public members
#include
using namespace std ;
class Line
{ public:
double length;
void setLength(double len);
double getLength();
};
double Line::getLength(void )
{
return length;
}
void Line::setLength(double len)
{
length = len;
}
int main()
{
Line obj;
obj.setLength(100);
cout
-
8/17/2019 Class Access Modifiers
2/3
-
8/17/2019 Class Access Modifiers
3/3
// The protected members:
#include
using namespace std ;
class o$
{ protected :
double &idth;
};
class mallo$:o$
{ public:
void setmall%idth(double &id);
double getmall%idth();
};
void mallo$::setmall%idth(double &id)
{ &idth = &id;
}
double mallo$::getmall%idth()
{
return &idth;
}
int main()
{
mallo$ obj;
obj.setmall%idth(100);
cout