#include "stdafx.h"
template <typename T>
class E
{
public:
T val;
int errcode;
E(){}
E(const T& val)
{
val = val;
}
operator T() const
{
return val;
}
operator T*()
{
return &val;
}
E<T> operator=(const T& _val)
{
val = _val;
return *this;
}
public:
int fail() const
{
return errcode;
}
};
E<int> GetResult(bool fail)
{
E<int> obj;
obj.val = 0x1000;
obj.errcode = fail;
return obj;
}
int _tmain(int argc, _TCHAR* argv[])
{
E<int> a;
a.val = 5;
a.errcode = false;
int b = a;
int* c = a;
*c = 7;
const int* d = a;
unsigned int e = a = 8;
E<int> x = GetResult(true);
if (x.fail())
printf("error \r\n");
else
printf("succeed \r\n");
if (a.fail())
printf("error \r\n");
return 0;
}