Search code examples
c++listvectorint

Could not convert '{1, 2 ,3, 4, 5, 6}' to list<int> C++?


I am new to this and I'm doing some research on lists, vectors etc.

[Error] in C++98 'val' must be initialized by constructor, not by '{...}'

[Error] could not convert '{1, 2, 3, 4, 5, 6}' from <'brace-enclosed initializer list'> to 'std::list'

The error comes from the line:

list<int> val = {1,2,3,4,5,6};

Is there any reason as to this happening or am I just missing the big picture? Any help will be appreciated, kindest regards!


Solution

  • initializer_list is C++ 11 feature, it might be possible it is not available in C++98( may the tool chain you are using ) which is giving this error.