Granting Access In C++
When
a base class is inherited as private, all public and protected members of that
class become private members of the derived class. However, in certain
circumstances, you may want to restore one or more inherited members to their
original access specification.
Fig: Granting Access In C++ |
Syntax:
class
base class
{
private:
----------
public:
---------
};
class
derived: public base class
{
baseclass::member1;
baseclass::member2;
baseclass::function
name;
};
Program:
#include<iostream.h>
#include<conio.h>
class
base
{
private:
int i;
public:
int
j,k;
void
set(int x)
{
i=x;
}
int
get()
{
return(i);
}
};
class
derived: public base
{
public:
base::j;
base::set;
base::get;
int
a;
};
void
main()
{
derived
db;
db.j=20;
db.a=40;
db.set=(10);
cout<<db.get()<<”
“<<db.j<<” “<<db.a;
getch();
}
No comments:
Post a Comment