Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.law/visibility2.C

raw
1 // { dg-do assemble }
2 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
3 // GROUPS passed visibility
4 #include <iostream>
5
6
7
8 class base {
9 //==========
10
11 void base_priv(const char * n)
12 { std::cout << "base_priv called from: " << n << "\n"; }
13
14 protected:
15
16 void base_prot(const char * n)
17 { std::cout << "base_prot called from: " << n << "\n"; }
18
19 public:
20
21 void base_publ(const char * n)
22 { std::cout << "base_publ called from: " << n << "\n"; }
23
24 void test(const char * n) { base_publ(n); base_prot(n); base_priv(n); }
25
26 }; // class base
27
28
29
30 class derived : public base { // Make this public,
31 //============================ // and we don't get an error
32
33 friend void derived_friend();
34
35 public :
36
37 void test(const char * n) { base_publ(n); base_prot(n);}
38
39 }; // class derived
40
41
42
43 void
44 derived_friend()
45 //--------------
46 {
47 derived pd;
48
49 pd.base_publ("friend of derived class"); // Compiler error here
50 pd.base_prot("friend of derived class");
51 }
52
53
54
55 int main(int argc, char *argv[])
56 //==========================
57 {
58 base b;
59 b.base_publ("base class object");
60 b.test("member of base class object");
61 std::cout << "\n";
62
63 derived pd;
64 pd.test("member of derived class object");
65 derived_friend();
66 std::cout << "\n";
67
68 } /* main */
69