T
thinktwice
template <class T>
class CThrowable
{
protected:
virtual void Assign(T val)
{
m_val = val;
if (IsBad())
{
throw val;
}
}
virtual bool IsBad() const
{
return false;
}
T m_val;
};
class CThrowableHRESULT : public CThrowable<HRESULT>
{
public:
CThrowableHRESULT(HRESULT val)
{
Assign(val);
}
protected:
bool IsBad()
{
return !SUCCEEDED(m_val);
}
};
class CThrowableBoolean : public CThrowable<bool>
{
public:
CThrowableBoolean(bool val)
{
Assign(val);
}
protected:
bool IsBad()
{
return !m_val;
}
};
CThrowableBoolean tBoolean(true);
tBoolean = false; //won't throw, actually it calls IsBad which is in
the base class ,why?
CThrowableHRESULT tHRESULT(S_OK);
tHRESULT = E_FAIL; //won't throw ,
class CThrowable
{
protected:
virtual void Assign(T val)
{
m_val = val;
if (IsBad())
{
throw val;
}
}
virtual bool IsBad() const
{
return false;
}
T m_val;
};
class CThrowableHRESULT : public CThrowable<HRESULT>
{
public:
CThrowableHRESULT(HRESULT val)
{
Assign(val);
}
protected:
bool IsBad()
{
return !SUCCEEDED(m_val);
}
};
class CThrowableBoolean : public CThrowable<bool>
{
public:
CThrowableBoolean(bool val)
{
Assign(val);
}
protected:
bool IsBad()
{
return !m_val;
}
};
CThrowableBoolean tBoolean(true);
tBoolean = false; //won't throw, actually it calls IsBad which is in
the base class ,why?
CThrowableHRESULT tHRESULT(S_OK);
tHRESULT = E_FAIL; //won't throw ,