Jump to content
  • Advertisement
Sign in to follow this  
KittyRa

auto Keyword

This topic is 4699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some questions about the auto keyword. 1) I have seen declarations like this:
auto int i = 0;
What does the auto do? 2) I have also seen this:
v is a vector

for (auto i = v.begin(); i != v.end(); ++v)
     // do something here...
where the auto keyword detects that v is a vector and initializes i accordingly (or something like that though I think that might be C++0x). Can you do this with C++98? 3) If, like in the last example, auto automatically detects the type of v, could I do something like this:
int integer = 23145496;
auto automajigger = integer;
Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
1) It means it's a stack variable. It's basically pointless.

2) That's C++0x code, you can't do it with C++98.

3) If you had a C++0x compiler.

Share this post


Link to post
Share on other sites
register and auto are both storage-class specifiers (as are static and extern) so I would consider them to be complementary. Not necessarily opposites, but complementary.

Share this post


Link to post
Share on other sites
They are not "opposites"; there is a third option for local storage - static, and you could always put stuff on the freestore instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!