fork download
  1. #include <iostream>
  2. using namespace std;
  3. class base1
  4. {
  5. public:
  6. int a;
  7. virtual int reset(){
  8. a=0;
  9. return a;
  10. }
  11. };
  12.  
  13. class derived1: public base1
  14. {
  15. public:
  16. int b;
  17. int reset(){
  18. b=0;
  19. return b;
  20. }
  21.  
  22. };
  23.  
  24. template <class T>
  25. class templateClass{
  26. public:
  27. T *P;
  28.  
  29. T& operator = (templateClass &b )
  30. {
  31. this.p = reinterpret_cast<T>(b.p);
  32. return *this;
  33. }
  34.  
  35. void resetMyself(){
  36. P->reset();
  37. }
  38. };
  39.  
  40. int main() {
  41. // your code goes here
  42. templateClass<base1> *p = new templateClass<base1> () ;
  43. templateClass<derived1> *q = new templateClass<derived1>() ;
  44. p=q;
  45.  
  46. p->resetMyself();
  47.  
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:44:3: error: cannot convert ‘templateClass<derived1>*’ to ‘templateClass<base1>*’ in assignment
  p=q;
   ^
stdout
Standard output is empty