Template Function For Pass-By-Reference and Pass-By-Pointer

In C++, is it possible to have a single template function that allows both pass-by-reference and pass-by-pointer?

For example, I have:

template<class T>
void displayArray(const T *array, const int count)

and

template<class T>
void displayArray(const T &array, const int count)

The first is used for int, double and char arrays as the variables are pointers to the first element in the array. The second is used on a specialized array class that I made where the passed in variable is not a pointer. Is it possible to combine these two into a single template function or do I just have to overload it? The actual implemention bodies are identical. Thanks.
Last edited on
If the bodies are the same, you don't need to have two functions. Passing a pointer to the second would work fine I believe.
Unfortunately the second one won't work with arrays of ints, doubles, etc. So right now I have this template function overloaded when I wish I could condense it down to only one version.
Topic archived. No new replies allowed.