const char*
为什么从to的隐式转换std::string
在后一种情况下不起作用?如果可能,请链接对 C++ 标准的引用。
变体 1:
struct Foo {
Foo(const char* a) {}
};
int main() {
// works well for a "const char*" accepting constructor
Foo* foo = new Foo[1] { "a" };
}
变体 2:
struct Foo {
Foo(std::string a) {}
};
int main() {
// could not convert from "const char*" to "Foo"
Foo* foo = new Foo[1] { "a" };
}