Advertisement
Bruce314

class.cpp

Nov 17th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include "class2.hpp"
  3.  
  4. class B {
  5. public:
  6.   virtual int BMethod(int x)=0;
  7.  
  8. };
  9. class D{
  10. public:
  11.   virtual int DMethod(int x)=0;
  12. };
  13. class A:public B,public C, public D
  14. {
  15. public:
  16. virtual int CMethod(int x) {return x+2;}
  17. virtual int BMethod(int x) {return x+1;}
  18. virtual int DMethod(int x) {return x+3;}
  19. };
  20.  
  21.  
  22. int main (void)
  23. {
  24.  A* a=new A();
  25.  Test* t= new Test();
  26.  
  27.  std::cout << a->CMethod(8) << std::endl;
  28.  
  29.  C* c;
  30.  c= (C*) a;
  31.  std::cout << t->test(c,8) << std::endl;
  32.  
  33.  c= static_cast<C*>( a);
  34.  std::cout << t->test(c,8) << std::endl;
  35.  
  36.  c= dynamic_cast<C*>( a);
  37.  std::cout << t->test(c,8) << std::endl;
  38.  
  39.  B* b;
  40.  b= (B*) a;
  41.  std::cout << b->BMethod(8) << std::endl;
  42.  
  43.  b= static_cast<B*>( a);
  44.  std::cout << b->BMethod(8) << std::endl;
  45.  
  46.  b= dynamic_cast<B*>( a);
  47.  std::cout << b->BMethod(8) << std::endl;
  48.  
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement