OSDN Git Service

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