I am having trouble getting a template function to recognise that it has been passed a reference by a calling template function. This example code demonstrates the problem.
The problem is that the failure to recognise that a string reference is passed through the template functions, is causing the string copy constructor to be called. This is hitting performance.Code:template<typename T>outputData<T data> { cout<<data<<endl; } template<typename T>displayData<T data> { outputData(data) } int main() { string name("Muppet"); string &reference=name; displayData(reference); }
Do I have to explicitly declare overrides of the template functions that explicity declare reference arguments? I think this will likley yield ambiguity when the compiler tries to resolve which override of a template to use to generate the explicit vrsion of the code to match the arguments passed.