Hi all! I would like to ask you for an advice about function template. I have a function that adds some data into buffer. But I need also to add an information about data type into the buffer. The type of data is a following enum:
enum ParameterType
{
UINT,
FLOAT,
DOUBLE
};
And I need to create a function template from function like this:
void SomeBuffer::append( double par )
{
appendType( DOUBLE );
memcpy( pStr + _length, &par, sizeof( double ) );
_length += sizeof( double );
appendType( DOUBLE );
}
Could you please advice me how to pass a value from ParameterType for appendType() depending on type of parameter.
template<class T>
void SomeBuffer::append( T par )
{
appendType( ??? );
memcpy( pStr + _length, &par, sizeof( T ) );
_length += sizeof( T );
appendType( ??? );
}
I tried to do it by some macros but without success. Thank you very much for any advice.