Home | History | Annotate | Download | only in class_types
      1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 class Conversion
     11 {
     12 public:
     13     Conversion (int i) :
     14       m_i (i)
     15       {}
     16 
     17     operator bool()
     18     {
     19         return m_i != 0;
     20     }
     21 
     22 private:
     23     int m_i;
     24 };
     25 
     26 class A
     27 {
     28 public:
     29     A(int i=0):
     30         m_a_int(i),
     31         m_aa_int(i+1)
     32     {
     33     }
     34 
     35     //virtual
     36     ~A()
     37     {
     38     }
     39 
     40     int
     41     GetInteger() const
     42     {
     43         return m_a_int;
     44     }
     45     void
     46     SetInteger(int i)
     47     {
     48         m_a_int = i;
     49     }
     50 
     51 protected:
     52     int m_a_int;
     53     int m_aa_int;
     54 };
     55 
     56 class B : public A
     57 {
     58 public:
     59     B(int ai, int bi) :
     60         A(ai),
     61         m_b_int(bi)
     62     {
     63     }
     64 
     65     //virtual
     66     ~B()
     67     {
     68     }
     69 
     70     int
     71     GetIntegerB() const
     72     {
     73         return m_b_int;
     74     }
     75     void
     76     SetIntegerB(int i)
     77     {
     78         m_b_int = i;
     79     }
     80 
     81 protected:
     82     int m_b_int;
     83 };
     84 
     85 #include <cstdio>
     86 class C : public B
     87 {
     88 public:
     89     C(int ai, int bi, int ci) :
     90         B(ai, bi),
     91         m_c_int(ci)
     92     {
     93         printf("Within C::ctor() m_c_int=%d\n", m_c_int); // Set break point at this line.
     94     }
     95 
     96     //virtual
     97     ~C()
     98     {
     99     }
    100 
    101     int
    102     GetIntegerC() const
    103     {
    104         return m_c_int;
    105     }
    106     void
    107     SetIntegerC(int i)
    108     {
    109         m_c_int = i;
    110     }
    111 
    112 protected:
    113     int m_c_int;
    114 };
    115 
    116 int
    117 main (int argc, char const *argv[])
    118 {
    119     A a(12);
    120     B b(22,33);
    121     C c(44,55,66);
    122     Conversion conv(1);
    123     if (conv)
    124         return b.GetIntegerB() - a.GetInteger() + c.GetInteger();
    125     return 0;
    126 }
    127