누군가가 내게이 이론을 말해 줄 수 있습니까?생성자 및 initializer_list
마지막 호출이 컴파일되지 않는 이유는 무엇입니까?
test.cc: In function ‘int main()’: test.cc:15:12: error: too many braces around initializer for ‘int’ [-fpermissive] test.cc:15:12:
error: invalid conversion from ‘’ to ‘int’ [-fpermissive] test.cc:9:6: error: initializing argument 1 of ‘void f(std::initializer_list)’ [-fpermissive] test.cc:15:12:
error: aggregate value used where an integer was expected
는 나도 C++ 11 g ++ 4.7이 깨진 생각합니다. 감사합니다.
#include <initializer_list>
class A {
public:
A(const std::initializer_list<int>) {}
};
void f(const std::initializer_list<int>) {}
int main() {
A({1}); // Compile OK
f({1}); // Compile OK
A({{{1}}}); // Compile OK
//f({{{1}}}); // Compile Error.
}
감사합니다. 나는 C++ 11의 stardard 헤더 initializer_list에 대해 이야기하고있다. – yufanyufan
흥미 롭습니다. Clang은 두 경우 모두 여분의 괄호에 대한 경고를 던집니다. – soon