-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinheritance5.cpp
More file actions
47 lines (44 loc) · 859 Bytes
/
Copy pathinheritance5.cpp
File metadata and controls
47 lines (44 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Granting Access
1) General form:- base-class::Member;
2) By coding "Using" statement
3) By an access declaration within derived class
*/
// 1) General form:- base-class::Member;
// this method is depricated and does not work in new
// C++ versions
#include<iostream>
using namespace std;
class Base
{
int i;
public:
int j,k;
void seti(int x)
{
i=x;
}
int geti()
{
return i;
}
};
class derived:private Base
{
public:
Base::j;
Base::seti;
Base::geti;
//Base::i; //illegal statement(cannot change original private to public)
int a;
};
int main()
{
derived ob;
//ob.i=10;// illegal (cannot access private)
ob.j=20;
//ob.k=30;// illegal(not changed back to public in class derived)
ob.a=40;
ob.seti(10);
cout<<ob.geti()<<" "<<ob.j<<" "<<ob.a<<endl;
}