当我编译下面的代码时有一个奇怪的行为:
class Foo {
};
int main() {
Foo(b);
}
Run Code Online (Sandbox Code Playgroud)
即使没有b. 对此有什么解释吗?
struct A
{
operator int() { return 12;}
};
struct B
{
B(int) {}
};
int main()
{
....
A a;
B b0 = 12;
// B b1 = a; //< error: conversion from 'A' to non-scalar type 'B' requested
B b2{a}; // < identical, calling A::operator int(), then B::B(int)
B b3 = {a}; // <
auto b4 = B{a}; // <
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是