Quick q,

What function takes precedence with a template function vs a non-template function?

I set up the following code but my result had the following output
Template
Template
even though a guide I read said it should read:
Template
Non-template

// Testing template function vs non-template function to see which function takes precedence when overloaded
template<class T>
void output(T x, T y)
{
	cout << "Template" << endl;
}

void output(string x, string y)
{
	cout << "Non-Template" << endl;

void main()
{
	output(1,5); // I understand Template is output since
// the non-template function has arguments of type string
	output("1", "k"); // ?
}
}

>>output("1", "k"); // ?

should be a string :

output(string("1"), string("k")); // ?

Whats happening is that "1" and "k" is being interpreted as a const char*

Edited 6 Years Ago by firstPerson: n/a

>>output("1", "k"); // ?

should be a string :

output(string("1"), string("k")); // ?

Whats happening is that "1" and "k" is being interpreted as a const char*

Thanks!

I've got #include <string> and thought that "xyz" would be interpretted as a string versus the single quotation marks ' ' which indicate its a const char* :-S ?

Thanks!

I've got #include <string> and thought that "xyz" would be interpretted as a string versus the single quotation marks ' ' which indicate its a const char* :-S ?

Nope, then it would be ambiguous.

This question has already been answered. Start a new discussion instead.