[Cs3] on declaring a variable in an expression of a branching statement

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Sep 25 15:28:16 EDT 2017


CS3 students,

You can declare (and initialize) a variable OR do other evaluation in
a branching statement, but not both. At least not until C++17. So

So, this

   auto location = months.find("january");
   if(location != months.end())
      ...

and this
   
   if(auto location = months.find("january"))
      ...

is legal. But this

   if(auto location = months.find("january") && location !=   months.end())

is not.

Thanks,
-- 
Mikhail


More information about the cs3 mailing list