0
#include <iostream>
using namespace std;
class base
{
public:
  virtual bool operator ==( const base& other ) =0;
};

class derived : public base
{
public:
  bool operator ==( const base& other ) { return false; }
  bool operator ==( const derived& other ) { return true; }
};


int main()
{
  base* a = new derived;
  base* b = a;
  std::cout << ( *a == *b ) << std::endl;
  cout<< (dynamic_cast< base*>(b) == dynamic_cast< base*>(a));

}

std::cout << ( *a == *b ) << std::endl;を呼び出しますが、出力に 1 が表示されるのDerived::operator==( const base& other )はなぜですか?cout << (dynamic_cast<base*>(b) == dynamic_cast<base*>(a));

4

0 に答える 0