The auto
keyword is not designed for this, declare data as:
void* data;
Then, you can just use an int or enum to keep track of the type of data. Such as,
typedef enum
{
CHAR,
SHORT
} DataTypeEnum;
...
DataTypeEnum dataType;
...
and modify your code as follows:
void some_func(int datasize)
{
//
case 8:
data = static_cast<void*>(new char[datasize]);
dataType = CHAR;
break;
case 16:
data = static_cast<void*>(new short[datasize]);
dataType = SHORT;
break;
//
etc.
}
...
if( dataType == CHAR )
{
...
}
else if ( dataType == SHORT )
{
...
}