fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. using std::cout;
  5. using std::endl;
  6.  
  7. struct C;
  8.  
  9. struct B
  10. {
  11. long unsigned int hash;
  12.  
  13. B(C *c);
  14.  
  15. virtual ~B() = default;
  16. };
  17.  
  18. struct C : B
  19. {
  20. C() : B(this)
  21. {
  22. cout << "C()" << endl;
  23. }
  24. };
  25.  
  26. B::B(C *c)
  27. {
  28. hash = typeid(*c).hash_code(); //1, UB?
  29. }
  30.  
  31. C c;
  32. int main()
  33. {
  34. cout << c.hash << endl;
  35. cout << typeid(c).hash_code() << endl;
  36. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
C()
1621135011
3641736028