코드 고려해C++ 11 initializer_list 오류
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<std::string> v{{"awe", "kjh"}}; // not v{"awe", "kjh"}
std::cout << v.size() << std::endl;
return 0;
}
이 코드는 잘못인가? 아니면 벡터를 초기화하는 동안 double
{}
을 사용하는 것이 맞습니까?gcc와 MSVC에서이 코드를 시도했습니다. MSVC 2012 + 컴파일러 2011 년 11 월 컴파일 할 수 없습니다. 놀라운 일이 아닙니다. gcc 4.7 또는 4.8로 컴파일 된이 코드는 프로그램 실행 중 런타임 오류 을 제공합니다. 이 행동이 맞습니까?
다른 컴파일러로는 테스트 할 수 없습니다.
이 유용 할 수 있습니다 - http://stackoverflow.com/questions/11400090/c-why-initializer-list-behavior-for-stdvector-and-stdarray-are-different – Bill
참조 http://stackoverflow.com/questions/14587436/call-of-overloaded-brace-enclosed-initializer-list-is-ambiguous-how-to-deal-w 및 http://cplusplus.github.io/ LWG/lwg-active.html # 2238 (이 광고는 다른 광고와 관련이 있지만 매우 유사합니다.) –