Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base{
  5. public:
  6. class iImplement{
  7. public:
  8. virtual int func() = 0;
  9. };
  10.  
  11. Base(iImplement *impl): impl(impl) {}
  12.  
  13. bool func2(){
  14. return func() < 5;
  15. }
  16.  
  17. private:
  18. iImplement *impl;
  19.  
  20. int func(){
  21. return impl->func();
  22. }
  23. };
  24.  
  25. class Derived: public Base{
  26. public:
  27. class DerivedImplement: public iImplement{
  28. public:
  29. int func() final {
  30. // sugoi syori
  31. return 10;
  32. }
  33. };
  34.  
  35. Derived(iImplement *impl=new DerivedImplement()): Base(impl) {}
  36. };
  37.  
  38. class TestSuite{
  39. public:
  40. class TestImplement: public Base::iImplement{
  41. public:
  42. int func_value;
  43.  
  44. int func() final {
  45. // stub
  46. return func_value;
  47. }
  48. };
  49.  
  50. TestSuite(): t(new TestImplement), d(t){}
  51.  
  52. void run_test(){
  53. func2_test();
  54. }
  55. private:
  56. TestImplement *t;
  57. Derived d;
  58.  
  59. void func2_test(){
  60. t->func_value = 10;
  61. cout << d.func2() << endl;
  62.  
  63. t->func_value = 0;
  64. cout << d.func2() << endl;
  65. }
  66. };
  67.  
  68. int main(){
  69. TestSuite test;
  70. test.run_test();
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement