#include <iostream>
using namespace std;
template<class T> class CBase
{
public:
template <class T2> CBase(const T2 &x) : _var(x) {;}
template <class T2> CBase (const CBase<T2> &x) {_var = x.var();}
~CBase() {;}
T var() const {return _var;}
protected:
T _var;
};
template<class T> class CDerived : public CBase<T>
{
public:
template <class T2> CDerived(const T2 &x) : CBase<T>(x) {;}
template <class T2> CDerived(const CDerived<T2> &x) : CBase<T>(x.var()) {;}
template <class T2> CDerived (const CBase<T2> &x) : CBase<T>(x) {;}
~CDerived() {;}
};
int main()
{
CBase<double> bd(3);
CBase<int> bi(bd); // <- No problem
CDerived<double> dd1(3);
CDerived<double> dd2(dd1);
CDerived<int> di(dd1); // <- The problem is here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPGNsYXNzIFQ+IGNsYXNzIENCYXNlCnsKICAgIHB1YmxpYzoKICAgICAgICB0ZW1wbGF0ZSA8Y2xhc3MgVDI+IENCYXNlKGNvbnN0IFQyICZ4KSA6IF92YXIoeCkgezt9CiAgICAgICAgdGVtcGxhdGUgPGNsYXNzIFQyPiBDQmFzZSAoY29uc3QgQ0Jhc2U8VDI+ICZ4KSB7X3ZhciA9IHgudmFyKCk7fQogICAgICAgIH5DQmFzZSgpIHs7fQogICAgICAgIFQgdmFyKCkgY29uc3Qge3JldHVybiBfdmFyO30KICAgIHByb3RlY3RlZDoKICAgICAgICBUIF92YXI7Cn07Cgp0ZW1wbGF0ZTxjbGFzcyBUPiBjbGFzcyBDRGVyaXZlZCA6IHB1YmxpYyBDQmFzZTxUPgp7CiAgICBwdWJsaWM6CiAgICAgICAgdGVtcGxhdGUgPGNsYXNzIFQyPiBDRGVyaXZlZChjb25zdCBUMiAmeCkgOiBDQmFzZTxUPih4KSB7O30KICAgICAgICB0ZW1wbGF0ZSA8Y2xhc3MgVDI+IENEZXJpdmVkKGNvbnN0IENEZXJpdmVkPFQyPiAmeCkgOiBDQmFzZTxUPih4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