fork download
  1. template<class T>
  2. class SomeTemplate
  3. {
  4. public:
  5. SomeTemplate(T* p) { pData = p; }
  6. T* getPointer() { return pData; }
  7. template<class S>
  8. SomeTemplate(SomeTemplate<S> s)
  9. {
  10. pData = s.getPointer();
  11. }
  12. private:
  13. T* pData;
  14. };
  15.  
  16. class A {};
  17. class B : public A {};
  18.  
  19. int main()
  20. {
  21. SomeTemplate<B> b(new B());
  22. SomeTemplate<A> a(b);
  23. SomeTemplate<B> bb(a);
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘SomeTemplate<T>::SomeTemplate(SomeTemplate<S>) [with S = A, T = B]’:
prog.cpp:23:   instantiated from here
prog.cpp:10: error: invalid conversion from ‘A*’ to ‘B*’
stdout
Standard output is empty