I am having problems with inheritance

I get there erros:
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
exercise5.cpp: In member function `void bClass::set(int, int, int)':
C:\Dev-Cpp\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\exercise5.cpp:48: error: within this context
C:\Dev-Cpp\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\exercise5.cpp:48: error: within this context

C:\Dev-Cpp\exercise5.cpp:13: error: `int aClass::v' is private
C:\Dev-Cpp\exercise5.cpp:49: error: within this context
C:\Dev-Cpp\exercise5.cpp:13: error: `int aClass::v' is private
C:\Dev-Cpp\exercise5.cpp:49: error: within this context
C:\Dev-Cpp\exercise5.cpp: In member function `void bClass::print()':
C:\Dev-Cpp\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\exercise5.cpp:56: error: within this context

C:\Dev-Cpp\Chapter2\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:56: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp:13: error: `int aClass::v' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:56: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp:13: error: `int aClass::v' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:56: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp: In member function `int cClass::sum()':
C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: `z' undeclared (first use this function)
C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Dev-Cpp\Chapter2\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp:12: error: `int aClass::u' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp:13: error: `int aClass::v' is private
C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: within this context
C:\Dev-Cpp\Chapter2\exercise5.cpp:13: error: `int aClass::v' is private

C:\Dev-Cpp\Chapter2\exercise5.cpp:68: error: within this context

Execution terminated


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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  #include<iostream>
using namespace std;

class aClass
{
public:
    void print() const;
    void set(int, int);
     aClass();
     aClass(int, int);
private:
   int u;
   int v;
};
aClass::aClass()
{
    u = 0;
    v = 0;
} 
aClass::aClass(int, int)
{
      u = 999;
      v = 1000;
}
void aClass::set(int, int)
{
     u = 999;
     v = 1000;
}     
 void aClass::print() const
{
     cout << "u = " << u  <<endl;
     cout << "v = " << v << endl;
}                                 
//What is wrong with the following class definitions?
//a. class bClass public aClass
class bClass : public aClass
{
public:
void print();
void set(int, int, int);
private:
int z;
};
void bClass::set(int, int, int)
{
       z = 4;
       u = 5;
       v = 6;
} 
void bClass::print()
{    
//b. class c Class: public aClass
aClass::print();
   cout<<"in bClass: z = "  
       <<  z << "u = "<< u << "v = " << v <<endl;
}       
class cClass: public aClass
{
public:
void print();
int sum();
cClass();
cClass(int);
};
 int cClass::sum()
{
     return(z + u + v);
}
void cClass::print()
{
     cout <<"The sum = " << sum() <<endl;
}                  

         
int main()
{
     aClass myObject;     
     myObject.set(34, 54);
     myObject.print();
     cClass thisSum;
     
     thisSum.set(34, 54);
     thisSum.sum();
     thisSum.print();
}     
In bClass you cannot access the private data of aClass (directly). That's basically the point of the private: statement.
Thank you all!!!
Sorted out the problem eventually
Topic archived. No new replies allowed.