N
Ninan
When compiling using gcc 2.95.3, I get the following error for the
code snippet posted below.
bash-2.03$ g++ membAccess.C
membAccess.C: In function `int main()':
membAccess.C:13: `struct A B::m_a' is private
membAccess.C:38: within this context
Is this how it is supposed to work or is this a compiler specific issue
1 #include <iostream>
2
3
4 struct A
5 {
6 int y;
7 };
8
9 void useAalter (A* pA);
10 class B
11 {
12
13 A m_a;
14 public:
15 B (A& a)
16 {
17 m_a = a;
18 }
19 A* getA () { return &m_a;}
20 friend void useAalter(A*pA);
21 };
22
23 void useA (A* pA)
24 {
25 std::cout << pA->y << std::endl;
26 }
27
28 void useAalter (A* pA)
29 {
30 std::cout << pA->y << std::endl;
31 }
32
33 int main ()
34 {
35 A a = {45};
36 B bInst (a);
37 useA (bInst.getA());
38 useAalter (&(bInst.m_a)) ;
39 }
code snippet posted below.
bash-2.03$ g++ membAccess.C
membAccess.C: In function `int main()':
membAccess.C:13: `struct A B::m_a' is private
membAccess.C:38: within this context
Is this how it is supposed to work or is this a compiler specific issue
1 #include <iostream>
2
3
4 struct A
5 {
6 int y;
7 };
8
9 void useAalter (A* pA);
10 class B
11 {
12
13 A m_a;
14 public:
15 B (A& a)
16 {
17 m_a = a;
18 }
19 A* getA () { return &m_a;}
20 friend void useAalter(A*pA);
21 };
22
23 void useA (A* pA)
24 {
25 std::cout << pA->y << std::endl;
26 }
27
28 void useAalter (A* pA)
29 {
30 std::cout << pA->y << std::endl;
31 }
32
33 int main ()
34 {
35 A a = {45};
36 B bInst (a);
37 useA (bInst.getA());
38 useAalter (&(bInst.m_a)) ;
39 }