Why does dynamic_cast<new>(old) change old?
Example code:
#include <iostream>
#include <string>
class MyInterface {
public:
  virtual void say() = 0;  
  virtual ~MyInterface() { }
};
class SubInterface : public MyInterface {
public:
  std::string test = "test";
  virtual void say() = 0;
  virtual ~SubInterface() { }
};
class Example : public SubInterface { 
public:
  void say() {
    std::cout << test << std::endl;
  } 
}; 
int main() {
  MyInterface* ex1 = new Example(); 
  SubInterface* ex2 = dynamic_cast<SubInterface*>(ex1);
  if (ex2 != nullptr) {
    std::cout << "call ex2->say(): ";
    ex2->test = "something else";
    ex2->say();
  }
  else { 
    std::cout << "error" << std::endl;
  }
  std::cout << "call ex1->say(): ";
  ex1->say();
  std::cerr << "debug: ex1=" << ex1 << "; ex2=" << ex2 << std::endl;
  return 0;
}
Which outputs:
call ex2->say(): something else
call ex1->say(): something else
debug: ex1=0xf1e010; ex2=0xf1e010
So I expected ex2 to be different from ex1 and therefore expected ex2->test = "something else"; not to change ex1. I guess this is intended behaviour, but why? (If they are not different, why would it even be necessary to assign anything to the result of dynamic_cast? (One could keep on using ex1?))
Any help is appreciated.
 
     
     
     
     
    