I want to make a generic Array function. In my API, I have generic container that I need to cast to the right class, but I want to make it generic
template<class T>
void UT::printArray(CCArray* arr, T type)
{
CCObject *aIt = NULL;
CCARRAY_FOREACH(arr,aIt )
{
T *aElm = static_cast<T*>(aIt );
int col = aElm ->getColNum();
int row = aElm ->getRowNum();
CCLOG("col:%d row:%d",col,row);
}
}
This does not compile right, and also I need to make new T object each time I call this function. What is the right way for this?