Advertisement
kenpusney

crtp.cpp

Oct 17th, 2022 (edited)
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.27 KB | None | 0 0
  1. class Super {};
  2.  
  3. template<class T>
  4. class Base {
  5.     public:
  6.     T* getT() {
  7.         return dynamic_cast<T*>(this);
  8.     }
  9.  
  10.     virtual ~Base() {}
  11. };
  12.  
  13.  
  14. class Derived: public Base<Derived>, Super {
  15. };
  16.  
  17.  
  18. int main() {
  19.     Derived derived {};
  20.     derived.getT();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement