I currently have the following code:
template< class Obj, class ObjResult >
CLStatus convertObjToResult2( const Obj & xFrom, ObjResult & xTo )
{
CLStatus eStatus = CLSTATUS_SUCCESS;
switch ( xTo.eType )
{
case CEPTFull:
xTo.xData.xFull = xFrom;
break;
case CEPTBrief:
eStatus = Convert( xFrom, xTo.xData.xBrief );
break;
default:
eStatus = CLSTATUS_INVALIDPROJECTIONTYPE;
}
return eStatus;
}
template< class Obj, class ObjResult >
CLStatus convertObjToResult1( const Obj & xFrom, ObjResult & xTo )
{
CLStatus eStatus = CLSTATUS_SUCCESS;
switch ( xTo.eType )
{
case CEPTFull:
xTo.xData.xFull = xFrom;
break;
default:
eStatus = CLSTATUS_INVALIDPROJECTIONTYPE;
}
return eStatus;
}
All ObjResults have an xFull
, but only some have an xBrief
, where xData is a union
. This resulted in me writing the two different templates above, but it would be great if I could somehow have just one template.
I can't simply use convertObjToResult2
, since it will fail to compile with object types that do not have an xBrief
. I looked at this answer to see if it would help, but I don't understand at all what it's doing.