This issue is related to the one discussed here .
I am trying to use a list of initializers to create an argument that needs to be passed to operator[] .
#include <string> #include <vector> struct A { std::string& operator[](std::vector<std::string> vec) { return vec.front(); } }; int main() { // ok std::vector<std::string> vec {"hello", "world", "test"}; A a; // error: could not convert '{"hello", "world", "test"}' to 'std::vector...' a[ {"hello", "world", "test"} ]; }
My compiler (GCC 4.6.1) complains:
g++ -std=c++0x test.cpp test.cpp: In function 'int main()': test.cpp:20:8: error: expected primary-expression before '{' token test.cpp:20:8: error: expected ']' before '{' token test.cpp:20:8: error: expected ';' before '{' token test.cpp:20:35: error: expected primary-expression before ']' token test.cpp:20:35: error: expected ';' before ']' token
Should this be valid C ++ 11?
Interestingly, when using operator() instead of operator[] it works.
source share