fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A;
  5. class B;
  6. class C;
  7.  
  8. class A
  9. {
  10. public:
  11. void Testme(A& other)
  12. {
  13. cout << "value from this: " << Value() << " value from other: " << other.Value();
  14. }
  15.  
  16. protected:
  17. virtual char const* Value() = 0;
  18. };
  19.  
  20. class B : public A
  21. {
  22. protected:
  23. char const* Value()
  24. {
  25. return "B class";
  26. }
  27. };
  28.  
  29. class C : public A
  30. {
  31. protected:
  32. char const* Value()
  33. {
  34. return "C class";
  35. }
  36. };
  37.  
  38. int main() {
  39. B b = B();
  40. C c = C();
  41. b.Testme(c);
  42. return 0;
  43. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
value from this: B class value from other: C class