For example, in this instance (the code is pretty self-explanatory):
enum types : bool
{
READ,
WRITE
};
template<typename T>
auto function(types i, T data)
{
static T datas;
if (i == WRITE)
{
datas = data;
}
else if (i == READ)
{
return datas;
}
}
int main()
{
function(WRITE, "hello");
std::cout << function(READ, NULL);
}
The expected output is:
hello
but it ends up in an exception.
Is there any way to fix this or is it not possible?