[initializer_list] Problem with using initializer_list as function parameter

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <initializer_list>
using namespace std;

void doSomething(std::initializer_list<int> list) {

}

int main() {
	doSomething({2,3,6,8});
	return 0;
}


I write a small piece of code like above. But I can not compile it successfully.
I try it both with and without the line "using namespace std", but nothing worked.
The error list:
Symbol 'initializer_list' could not be resolved


I use Eclipse CDT and GCC 4.9.1.

I hope somebody can find out the solution for this problem.
Thanks!
Last edited on
Do you have C++11 support turned on?
Your code compiles fine for me and online compilers.
http://coliru.stacked-crooked.com/a/27be4c4ad2477614
Last edited on
Thanks.

According to every tutorial, I see that code has no error. Unfortunately, it doesn't work for me. I just want to know whether somebody got this problem.

I've already added -std=c++0x. I had used many C++11 features successfully before, including initializer lists with vectors.
As I know, there is the correct initializer_list header in my computer. I can import this header by intellisense (maybe another name for autocomplete in Eclipse). But the intelisense shows me no result when i type "std::ini" and press Ctrl+Space.
I can use online compiler or Dev-C++ to compile and run it successfully.
Then how to solve this problem in Eclipse?
Last edited on
I've already added -std=c++0x.
Use -std=c++11
Topic archived. No new replies allowed.