c++ - Surprisingly useful use of the keyword auto -


i more little surprised fascinating discovery, , wondering how "safe" rely on it.

the auto keyword has historically been used since implicitly implied anyway:

{ auto int x=5; } 

is same as:

{ int x=5; } 

so poking way around stackoverflow, great site highly recommend. , discovered fascinating nugget: in new c++ can use auto infer type.

this sure reduce lot of typing. example, instead of this, working on right now:

 std::chrono::high_resolution_clock::time_point       t1 = std::chrono::high_resolution_clock::now(); 

i can instead:

 auto t2(std::chrono::high_resolution_clock::now()); 

so i'd know is.... how of habit building doing often?

the "auto" tag here on stackoverflow says keyword works when can "unambiguously deduced" type is. implies me quite safe , fine habit, long don't plan support compilers of older generations of language.

you can learn google has shared wisdom preferred use of 'auto' rest of us:

use auto avoid type names clutter. continue use manifest type declarations when helps readability, , never use auto local variables.

read more @ http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#auto


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -