can I use auto with g++ 4.4?

▼魔方 西西 提交于 2019-12-11 02:15:13

问题


I can specify -std=c++0x for compilation with my g++ 4.4, and initializer lists are correct, I may use them (in c++98 I can't) but still get errors when try use auto keyword:

std::list< std::vector<int> > li2;

li2.push_back({1, 2, 3}); //push_back vector
li2.push_back({4, 2, 6}); //again, vector implicitly

for (auto& vv : li2) {
    for (auto &i : v)
        printf("element: %d\n", 8);

}

so I assume I can't use C++11 functionallities with g++4.4. I have 4.4 because of compatibility with CUDA.


回答1:


This link shows you the different C++11 features supported by GCC. auto appeared in GCC 4.4.

Your real problem is probably that the ranged-based for loop appeared only in GCC 4.6.



来源:https://stackoverflow.com/questions/16225550/can-i-use-auto-with-g-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!