Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "auto" keyword for std::list iterator with GCC

Tags:

c++

gcc

c++11

I am writing C++ app which should be compiled both using MS C++ on Windows and GCC on Linux.I wrote a loop on Windows which iterates through std::list:

 auto  iter = container.GetObj()->begin();
 while (iter!=container.GetObj()->end()){

   (*(iter++))->Execute();

 }

It works fine ,but when compiling it with GCC "auto" gets not recognized:

Unexptected token "auto" (in NetBeans IDE)

So I fixed it defining the iterator "explicitly :

 std::list<Container*>::iterator iter=container.GetObj()->begin();
 while (iter!=container.GetObj()->end()){

   (*(iter++))->Execute();

 }

My GCC version is 4.7.2

Does it mean that GCC doesn't support auto keyword ?May be I need to upgrade the compiler?

like image 528
Michael IV Avatar asked Dec 12 '25 14:12

Michael IV


1 Answers

Here is a link to gcc c++ 11 support. You also need to add -std=c++11 to your command line.

like image 119
rerun Avatar answered Dec 14 '25 02:12

rerun