Implicit cast from const string to bool

Viewed 2596

I have the following code:

#include <iostream>
#include <string>

void foo(bool a)
{
        std::cout << "bool" << std::endl;
}

void foo(long long int a)
{
        std::cout << "long long int" << std::endl;
}

void foo(const std::string& a)
{
        std::cout << "string" << std::endl;
}

int main(int argc, char* args[])
{
        foo("1");
        return 0;
}

When executing I get this output:

bool

I would have expected as output:

string

Why does g++ 4.9 implicitly cast this string to bool?

3 Answers
Related