fork download
  1. struct B {};
  2. struct D : B {};
  3.  
  4. template<typename T>
  5. class MyPtr
  6. {
  7. public:
  8. MyPtr(T* t) : t(t) {}
  9.  
  10. template <typename U>
  11. MyPtr(U*) = delete;
  12.  
  13. MyPtr operator = (T* t) { this->t = t; }
  14.  
  15. template <typename U>
  16. MyPtr operator = (U* t) = delete;
  17.  
  18. operator T* () const { return t; }
  19.  
  20. private:
  21. T* t;
  22. };
  23.  
  24. int main()
  25. {
  26. D d;
  27. B* bd = &d;
  28. MyPtr<B> pd = &d;
  29. MyPtr<B> n = nullptr;
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:28:20: error: use of deleted function 'MyPtr<T>::MyPtr(U*) [with U = D; T = B]'
     MyPtr<B> pd = &d;
                    ^
prog.cpp:11:5: note: declared here
     MyPtr(U*) = delete;
     ^
stdout
Standard output is empty