S
Simon Elliott
#include <iostream>
#include <string>
static void Test(const std::string& t)
{
std::cout << "std::string: " << t <<std::endl;
}
static void Test(bool t)
{
std::cout << "bool: " << t <<std::endl;
}
int main(int argc, char* argv[])
{
std::string t1 = "t1";
bool t2 = true;
char t3[] = "t3";
std::cout << "std::string" <<std::endl;
Test(t1);
std::cout << "bool" <<std::endl;
Test(t2);
std::cout << "char array" <<std::endl;
Test(t3);
return 0;
}
Output:
std::string
std::string: t1
bool
bool: 1
char array
bool: 1
Why does a call to Test with a char array map to
static void Test(bool t)?
I'd have expected it to either map to
static void Test(const std::string& t)
or give a compile time error.
#include <string>
static void Test(const std::string& t)
{
std::cout << "std::string: " << t <<std::endl;
}
static void Test(bool t)
{
std::cout << "bool: " << t <<std::endl;
}
int main(int argc, char* argv[])
{
std::string t1 = "t1";
bool t2 = true;
char t3[] = "t3";
std::cout << "std::string" <<std::endl;
Test(t1);
std::cout << "bool" <<std::endl;
Test(t2);
std::cout << "char array" <<std::endl;
Test(t3);
return 0;
}
Output:
std::string
std::string: t1
bool
bool: 1
char array
bool: 1
Why does a call to Test with a char array map to
static void Test(bool t)?
I'd have expected it to either map to
static void Test(const std::string& t)
or give a compile time error.