fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T>
  5. struct Base {
  6. int x;
  7. void print() {
  8. cout << "As Derived at " << static_cast<T*>(this) << ", as Base at " << this << ".\n";
  9. }
  10. };
  11. struct Derived: Base<Derived> { virtual ~Derived() {} };
  12.  
  13. int main()
  14. {
  15. Derived d;
  16. d.print();
  17. cout << "Real Derived at " << &d << ".\n";
  18. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
As Derived at 0xbfdc2e18, as Base at 0xbfdc2e1c.
Real Derived at 0xbfdc2e18.