Writing a Generic Function
-
I have 3 functions that do sorting on a CArray.
CArrays are declared in header file:
CArray<int*, int*>m_Integer;
CArray<string*, string*>m_String;
CArray<double*, double*>m_Double;void sortIntegers()
{// Do sorting for m_Integer here
}void sortStrings()
{
// DO sorting for m_String
}void sortDouble()
{
// Do sorting for m_Double
}Now what i want to do is, have one generic function and then pass the CArray to that.
So far what i did is,
in Header file:
void sortAll(CArray<void*, void*> m_Array);
in CPP file:
void sortAll(CArray<void*, void*> m_Array)
{
int size = m_Array.GetSize();............ ............ ............ m\_Array.GetAt(0); // Error here ................ ................
}
The error is that, it needs a class type and not a void type.
I am not sure how to proceed with writing a generic function to handle all different data types in one.
Any help is welcome!
-
I have 3 functions that do sorting on a CArray.
CArrays are declared in header file:
CArray<int*, int*>m_Integer;
CArray<string*, string*>m_String;
CArray<double*, double*>m_Double;void sortIntegers()
{// Do sorting for m_Integer here
}void sortStrings()
{
// DO sorting for m_String
}void sortDouble()
{
// Do sorting for m_Double
}Now what i want to do is, have one generic function and then pass the CArray to that.
So far what i did is,
in Header file:
void sortAll(CArray<void*, void*> m_Array);
in CPP file:
void sortAll(CArray<void*, void*> m_Array)
{
int size = m_Array.GetSize();............ ............ ............ m\_Array.GetAt(0); // Error here ................ ................
}
The error is that, it needs a class type and not a void type.
I am not sure how to proceed with writing a generic function to handle all different data types in one.
Any help is welcome!