1 // prms-id: 16146 2 3 extern "C" int printf (const char *, ...); 4 5 class myFoundation { 6 protected: myFoundation()7 myFoundation () { count = 0; }; ~myFoundation()8 virtual ~myFoundation () {}; 9 10 public: addRef()11 void addRef () { ++count; } removeRef()12 void removeRef () { if (count > 0) --count; } 13 14 private: 15 long count; 16 }; 17 18 19 class firstIntermediate :virtual public myFoundation { 20 public: firstIntermediate()21 firstIntermediate () {}; ~firstIntermediate()22 ~firstIntermediate () {}; 23 bar()24 void bar () { printf ("Bar\n"); } 25 }; 26 27 28 class firstBase : public firstIntermediate { 29 public: firstBase()30 firstBase () {}; ~firstBase()31 ~firstBase () {}; 32 g()33 virtual void g () {}; 34 }; 35 36 37 class secondIntermediate : virtual public myFoundation { 38 public: secondIntermediate()39 secondIntermediate () {}; ~secondIntermediate()40 ~secondIntermediate () {}; 41 h()42 virtual void h () {}; 43 }; 44 45 46 class secondBase : public secondIntermediate { 47 public: secondBase()48 secondBase () {}; ~secondBase()49 ~secondBase () {}; 50 h()51 virtual void h () {}; 52 }; 53 54 55 class typeInterface : virtual public firstBase { 56 public: typeInterface()57 typeInterface () {}; ~typeInterface()58 ~typeInterface () {}; 59 i()60 virtual void i () {}; 61 }; 62 63 class classServices : virtual public firstBase, 64 public secondBase { 65 public: classServices()66 classServices () {}; ~classServices()67 ~classServices () {}; 68 j()69 virtual void j () {}; 70 }; 71 72 class classImplementation : public typeInterface, 73 public classServices { 74 public: classImplementation()75 classImplementation () {}; ~classImplementation()76 ~classImplementation () {}; 77 g()78 void g () {}; h()79 void h () {}; i()80 void i () {}; j()81 void j () {}; 82 }; 83 main()84int main () { 85 firstBase* fbp = new classImplementation; 86 classImplementation* cip = dynamic_cast <classImplementation*> (fbp); 87 cip->addRef(); 88 myFoundation* mfp = cip; 89 } 90