K
Kamran
Hi
I am quite new in this so please bear with me.
I try to read some arrays of various types. I have
defined a function:
template <class T>
T* getArray(int size, int el_size)
which can be called like:
intehead_el = getArray<int>(no_in_el, sizeof(int));
or
intehead_el = getArray<double>(no_in_el, sizeof(double));
depending on the type of the array elements.
But the array element type itself is read from some
other variable in the input file.
My question is, is there a way which I could replace
the <class T> (int or double) with a generic name
when calling the function, depending on the type of
array element. Say that I just read the
type of the elements to be 'int' and this is stored
in a character array called 'type'. So then I would say:
intehead_el = getArray<type>(no_in_el, sizeof(type));
Thanks in advance
I am quite new in this so please bear with me.
I try to read some arrays of various types. I have
defined a function:
template <class T>
T* getArray(int size, int el_size)
which can be called like:
intehead_el = getArray<int>(no_in_el, sizeof(int));
or
intehead_el = getArray<double>(no_in_el, sizeof(double));
depending on the type of the array elements.
But the array element type itself is read from some
other variable in the input file.
My question is, is there a way which I could replace
the <class T> (int or double) with a generic name
when calling the function, depending on the type of
array element. Say that I just read the
type of the elements to be 'int' and this is stored
in a character array called 'type'. So then I would say:
intehead_el = getArray<type>(no_in_el, sizeof(type));
Thanks in advance