Template function parameters
From: nevlis (silven_at_removesilven.canada.com)
Date: 09/27/04
- Next message: Arnie Mauer: "Can objects have properties?"
- Previous message: Carl Daniel [VC++ MVP]: "Re: How to get processor serial number?"
- Next in thread: Doug Harrison [MVP]: "Re: Template function parameters"
- Reply: Doug Harrison [MVP]: "Re: Template function parameters"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 27 Sep 2004 14:45:12 GMT
I am trying to create a Template function that will take
differnet parameter types. However all my attempts have failed
can someone please tell me what I am doing wrong here is the code.
It seems to work when I pass integers however will not compile when
I have a float or double
I get this error when compiling
initializing : cannot convert from 'unsigned short *' to 'double'
I do not understand why it has unsigned short when I am passing
a double for the intData parameters
//function prototype
template <class Z>void StoreInArray(VARIANT* arr_rgElems,const
inDataType, Z inData, int intPosition);
//Test Calling this works
strcpy (strAsterisk, "*");
strTemp = A2BSTR(strAsterisk);
StoreInArray(rgElems,VT_BSTR, strTemp, intCounter++);
//this works
StoreInArray(rgElems,VT_I2, 99, intCounter++);
//I tried different many differnet ways but always get
//the same type of error when compiling
double tempX = 8.99
StoreInArray<double>(rgElems,VT_R8, tempX, intCounter++);
StoreInArray<double>(rgElems,VT_R8, (double)tempX, intCounter++);
StoreInArray(rgElems,VT_R8, (double)tempX, intCounter++);
//function
template <class Z> void StoreInArray(VARIANT* arr_rgElems,const
inDataType, Z inData, int intPosition){
COleDateTime myDateTime;
double douInData = inData;
VariantInit(&arr_rgElems[intPosition]);
arr_rgElems[intPosition].vt = inDataType;
switch (inDataType) {
case VT_BSTR:
arr_rgElems[intPosition].bstrVal = (BSTR) inData;
break;
case VT_I2:
arr_rgElems[intPosition].intVal = (int)inData;
break;
case VT_I4:
arr_rgElems[intPosition].intVal = (long)inData;
break;
case VT_R4:
arr_rgElems[intPosition].fltVal = (float)inData;
break;
case VT_R8:
arr_rgElems[intPosition].dblVal = (double)inData;
break;
case VT_DATE:
myDateTime = (time_t) *(long*)inData;
arr_rgElems[intPosition].date = (DATE)myDateTime;
break;
default:
break;
}
}
Thanks
nevlis
- Next message: Arnie Mauer: "Can objects have properties?"
- Previous message: Carl Daniel [VC++ MVP]: "Re: How to get processor serial number?"
- Next in thread: Doug Harrison [MVP]: "Re: Template function parameters"
- Reply: Doug Harrison [MVP]: "Re: Template function parameters"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|