fork(4) download
  1. #include <iostream>
  2.  
  3. struct Base
  4. {
  5. public:
  6. Base(int a) : _a(a) { }
  7. protected:
  8. int _a;
  9. bool operator == ( const Base& other ) const
  10. {
  11. return (_a == other._a);
  12. }
  13. };
  14.  
  15. struct Derived : public Base
  16. {
  17. Derived(int a) : Base(a) { }
  18. bool operator == ( const Derived& other ) const
  19. {
  20. return Base::operator==(other);
  21. //return static_cast<Base>(*this) == static_cast<Base>(other);
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. Derived b1(0), b2(0), b3(5);
  28. std::cout << std::boolalpha << (b1 == b2) << std::endl;
  29. std::cout << (b1 == b3) << std::endl;
  30. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
true
false