PageRenderTime 142ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 121ms

/trunk/Examples/test-suite/virtual_derivation.i

#
Swig | 67 lines | 39 code | 15 blank | 13 comment | 0 complexity | ee25d4e333e17a5f8c4dddf98a80bfc3 MD5 | raw file
 1%module virtual_derivation
 2
 3 /*
 4
 5 Try to add to your favorite language a runtime test like
 6 this:
 7 
 8 b = B(3)
 9 if (b.get_a() != b.get_b()):
10     print "something is wrong"
11
12
13 The test runs fine with python, but not with ruby.
14 
15 */
16
17%inline %{
18
19  struct A 
20  {
21    ~A()
22    {
23    }
24    
25    int m_a;
26    
27    A(int a) :m_a(a)
28    {
29    }
30    
31    int get_a()
32    {
33      return m_a;
34    }
35    
36  };
37  
38  struct B : virtual A
39  {
40    B(int a): A(a)
41    {
42    }
43    
44    int get_b()
45    {
46      return get_a();
47    }
48
49    // in ruby, get_a() returns trash if called from b, unless is
50    // wrapped with the previous get_b or using the 'using'
51    // declaration:
52    // using A::get_a;
53  };
54
55
56
57
58  class IndexReader{
59  public:
60    virtual void norms() = 0;
61  };
62
63  class MultiReader : public IndexReader {
64  protected:
65    MultiReader();
66  };
67%}