fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct A
  6. {
  7. char const* value() const
  8. {
  9. return valueImpl();
  10. }
  11. protected:
  12. virtual char const * valueImpl()
  13. { return "A"; }
  14. };
  15.  
  16. struct B
  17. {
  18. char const* value() const
  19. {
  20. return valueImpl();
  21. }
  22. protected:
  23. virtual char const * valueImpl() const
  24. { return "B"; }
  25. };
  26.  
  27. class C : public A, public B
  28. {
  29. public:
  30. using B::value;
  31.  
  32. };
  33.  
  34. int main()
  35. {
  36. C obj;
  37. cout << obj.value() << endl;
  38.  
  39. A * ptr = &obj;
  40. cout << ptr->value() << endl;
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 2828KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'const char* A::value() const':
prog.cpp:9:26: error: passing 'const A' as 'this' argument of 'virtual const char* A::valueImpl()' discards qualifiers
stdout

Standard output is empty