fork(11) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template<class T> class CBase
  6. {
  7. public:
  8. template <class T2> CBase(const T2 &x) : _var(x) {;}
  9. template <class T2> CBase (const CBase<T2> &x) {_var = x.var();}
  10. ~CBase() {;}
  11. T var() const {return _var;}
  12. protected:
  13. T _var;
  14. };
  15.  
  16. template<class T> class CDerived : public CBase<T>
  17. {
  18. public:
  19. template <class T2> CDerived(const T2 &x) : CBase<T>(x) {;}
  20. template <class T2> CDerived(const CDerived<T2> &x) : CBase<T>(x.var()) {;}
  21. template <class T2> CDerived (const CBase<T2> &x) : CBase<T>(x) {;}
  22. ~CDerived() {;}
  23. };
  24.  
  25. int main()
  26. {
  27. CBase<double> bd(3);
  28. CBase<int> bi(bd); // <- No problem
  29. CDerived<double> dd1(3);
  30. CDerived<double> dd2(dd1);
  31. CDerived<int> di(dd1); // <- The problem is here
  32. return 0;
  33. }
Success #stdin #stdout 0s 2780KB
stdin
Standard input is empty
stdout
Standard output is empty