fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. void bar(T t){};
  5.  
  6. int main() {
  7. //foo's type would be deduced as std::initializer_list<int>
  8. auto foo = {0, 1, 2, 3};
  9.  
  10.  
  11.  
  12. //compiles fine
  13. bar( foo );
  14.  
  15. //next line gives compiler error
  16. foo({0, 1, 2, 3});
  17.  
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:16:18: error: no match for call to '(std::initializer_list<int>) (<brace-enclosed initializer list>)'
  foo({0, 1, 2, 3});
                  ^
stdout
Standard output is empty