c++ - error: expected initializer before ‘:’ token -
i trying compile c++ code (which can compiled visual studio 2012 on windows) g++-4.4
.
i have snippet of code,
const std::string cnw::restoresession(const std::vector<string> &innwsfile) { (std::string &nwfile : innwsfile){ // some... } }
that cannot compile because of error:
cnwcontroller.cpp:154: error: expected initializer before ‘:’ token
can give me advise on how solve problem?
your compiler old support range-based for
syntax. according gnu first supported in gcc 4.6. gcc requires explicitly request c++11 support, giving command-line option -std=c++11
, or c++0x
on compilers old yours.
if can't upgrade, you'll need old-school equivalent:
for (auto = innwsfile.begin(); != innwsfile.end(); ++it) { std::string const &nwfile = *it; // const needed because innwsfile const //some... }
i believe auto
available in gcc 4.4 (as long enable c++0x support), save writing std::vector<string>::const_iterator
.
if need non-const
reference vector's elements then, whichever style of loop use, you'll need remove const
function parameter.
Comments
Post a Comment