The "auto" keyword in C++

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • Patreon ► / thecherno
    Twitter ► / thecherno
    Instagram ► / thecherno
    Discord ► thecherno.com/discord
    Series Playlist ► thecherno.com/cpp
    Thank you to the following Patreon supporters:
    - Dominic Pace
    - Kevin Gregory Agwaze
    - Sébastien Bervoets
    - Tobias Humig
    - Peter Siegmund
    - Kerem Demirer
    Gear I use:
    -----------------
    BEST laptop for programming! ► geni.us/pakTES
    My FAVOURITE keyboard for programming! ► geni.us/zNhB
    FAVOURITE monitors for programming! ► geni.us/Ig6KBq
    MAIN Camera ► geni.us/t6xyDRO
    MAIN Lens ► geni.us/xGoDWT
    Second Camera ► geni.us/CYUQ
    Microphone ► geni.us/wqO6g7K

ความคิดเห็น • 262

  • @AgentM124
    @AgentM124 6 ปีที่แล้ว +491

    I use auto to drive to my work

    • @will8090
      @will8090 6 ปีที่แล้ว +38

      I use my drive to auto work

    • @pixarfilmz4769
      @pixarfilmz4769 6 ปีที่แล้ว +37

      I auto drive my work to use

    • @marcdroz3369
      @marcdroz3369 6 ปีที่แล้ว +20

      auto_comment(!=creative){};

    • @bluehornet6752
      @bluehornet6752 4 ปีที่แล้ว +2

      My auto broke, so now I can't work...

    • @massiveblackwood
      @massiveblackwood 4 ปีที่แล้ว +1

      I work auto to drive home

  • @theguywhoiscoding9912
    @theguywhoiscoding9912 6 ปีที่แล้ว +297

    you can simplify the for-loop even more to:
    for (auto &string : strings)
    readability over 9000

    • @emilianzawrotny367
      @emilianzawrotny367 4 ปีที่แล้ว +47

      It is better to do for(const auto &string : strings)

    • @Alberto-ez4lr
      @Alberto-ez4lr 4 ปีที่แล้ว +18

      @@qatarking2498 means that you are using a reference of a string instead of making a copy of each string object for each iteration, that's would be so inefficient.

    • @adesva
      @adesva 4 ปีที่แล้ว +17

      He mentions for-range loops in the video and says it will be covered later in the series

    • @arthur1112132
      @arthur1112132 4 ปีที่แล้ว +9

      ​@@qatarking2498 & used at variable declaration is the 'reference' token in C++ In addition to the C 'get adress of' meaning everywhere else. so here, 'auto &string' means declare a variable reference of automatic type named "string" :)
      also, i think a for-range loop would have been a bad example of what he wanted to demonstrate since in that case, 'auto' refers to 'std::string' and he wanted to show how long an itterator can be

    • @shutout951
      @shutout951 3 ปีที่แล้ว +2

      Be careful that you don't write that loop when using namespace std; then you'll be overriding the name of the string variable inside the for loop.

  • @andrefaustino5514
    @andrefaustino5514 ปีที่แล้ว +32

    TIP: In current MVS2022, if you double click left ctrl, the inferred type will be displayed between auto and the name. It's a great tool for those who really wants to know the type of the variable but also wants a cleaner code. It's like you can alternate between inferred type and explicit type with one button.

    • @wang_7665
      @wang_7665 ปีที่แล้ว +8

      That's why I love this series so much. Firstly learned from the video itself, then learned from comments to grab new features.

    • @yousefbilal4837
      @yousefbilal4837 ปีที่แล้ว +5

      This has been updated to alt+f1 instead of double ctrl in newer versions

  • @LucidStew
    @LucidStew 6 ปีที่แล้ว +32

    Even though it got a bit off topic, I like the "you could do this, you could do that" part with using and typedef while explaining the use of auto to do something similar.

  • @dordan9987
    @dordan9987 4 ปีที่แล้ว +53

    15:00 How I feel about c++

    • @godnyx117
      @godnyx117 3 ปีที่แล้ว +3

      LMAO!!! 6 months later, how you feel now?

    • @AgentM124
      @AgentM124 3 ปีที่แล้ว +5

      @@godnyx117 You know why programmers have 2020 vision?
      It's cause they C++

    • @apotheos4783
      @apotheos4783 3 ปีที่แล้ว

      I still don't feel what you feel.

    • @adryelgainza1530
      @adryelgainza1530 3 ปีที่แล้ว +1

      Almost a year. How are you now?

  • @reshmamundamkotil7126
    @reshmamundamkotil7126 5 ปีที่แล้ว +47

    I feel blessed for finding this channel. Thank you man. I mean a lottttt.

    • @vivekkoul4428
      @vivekkoul4428 3 ปีที่แล้ว +1

      Hi how far have u reached with C++ now that it's already 2 years passed

  • @izukaa
    @izukaa 5 ปีที่แล้ว +51

    Hey, theCherno! Greetings from Romania, you're my first choice when comes to C++ tutorials. Nice job!

  • @Blure
    @Blure 4 ปีที่แล้ว +36

    I'll be spending the next few weeks watching your videos and brushing up my C++ skills. Thanks for sharing your knowledge!

    • @MuletTheGreat
      @MuletTheGreat 3 หลายเดือนก่อน

      How did you brushing up?

  • @VasaMusic438
    @VasaMusic438 5 ปีที่แล้ว +12

    again a great episode !! clear and full of real code experience !! Thank so much!!

  • @robertmoats1890
    @robertmoats1890 2 ปีที่แล้ว +12

    I'm a huge typedef fan when templated code results in messy or confusing typenames. I don't use auto very often, but I do like your usage for iterator typenames. In those cases, the auto keyword is unlikely to get you into any trouble. I think in most other cases, it actually IS likely to get you into trouble. It is a useful tool to help dig your own grave.

  • @christ4791
    @christ4791 6 ปีที่แล้ว +50

    You know the day is gonna be good when cherno uploads a video

  • @syirogane
    @syirogane ปีที่แล้ว +10

    I like "auto" (and its variants in other languages) for when the actual type is of little or no interest to me (though I generally avoid it for basic types), and the times the actual type is of no interest is when the algorithm itself is far more important than the actual types involved. Also, "auto" should be considered mandatory when the type is explicit elsewhere in the line (result of a cast, new, etc), but I don't consider 5.0 or 5f to be sufficiently explicit.

  • @fromscratch2654
    @fromscratch2654 2 ปีที่แล้ว +8

    I like to drive "stick shift" instead of "automatic" because it makes me feel like i have more control over my car. I belive the same goes for my coding. ;)

  • @silurust
    @silurust 3 ปีที่แล้ว +6

    Good explanation. Good guideposts.
    I can still remember a long cursing session from an experienced C++ programmer colleague when C++11 came out. When we asked why, the short answer was: "auto". His opinion was that the possible abuse significantly outweighs the benefits. (Perhaps, by time, he stopped having allergic reactions.)

  • @maishamolepo2216
    @maishamolepo2216 4 ปีที่แล้ว +7

    Really good video. A suggestion on what to make next: Data structures 😀

  • @abbudeh
    @abbudeh 6 ปีที่แล้ว +15

    Thanks for your great explanations. It would be great if you talk about lambdas and assertions in C++14 :)

  • @miteshsharma3106
    @miteshsharma3106 6 ปีที่แล้ว +112

    Talking about templates .....
    You said there will be many more videos on templates ... you could make that next !!

    • @tahamagdy4932
      @tahamagdy4932 5 ปีที่แล้ว

      SimGunther Hello Haskeller :D

    • @jerfersonmatos28
      @jerfersonmatos28 4 ปีที่แล้ว

      Thay are in the game engine series

  • @DanielLiljeberg
    @DanielLiljeberg 6 ปีที่แล้ว +11

    I was just about to write that auto is so nice when working with itterators for crazy collections :)

  • @PerchEagle
    @PerchEagle 5 ปีที่แล้ว +2

    I like the different possible options to do something ! so I can use auto, typedef or even define !
    but auto is a nice feature and it absolutely simplify things. Like small embedded projects that are easier to debug and also with using it, the code would be less prone to have errors or warnings.

  • @JayAnAm
    @JayAnAm 4 ปีที่แล้ว +8

    Nice explanation. One other use-case for auto is when migrating your C++ application to 64 Bit I would prefer auto over types like unsigned int that could behave in a different way for 32 Bit vs 64 Bit compilation.

    • @keris3920
      @keris3920 4 ปีที่แล้ว +4

      Use size_t for this. That is its purpose

    • @rastaarmando7058
      @rastaarmando7058 3 ปีที่แล้ว

      just use int64_t bro.

  • @OmarAbdelaziz__47
    @OmarAbdelaziz__47 4 ปีที่แล้ว +5

    two years ago of creating this video.
    Happy new year cherno!

  • @Brahvim
    @Brahvim 2 ปีที่แล้ว +3

    Smart pointers, and here we have these.
    _They're slowly making it JavaScript 🤣_

  • @smileynetsmileynet7922
    @smileynetsmileynet7922 3 ปีที่แล้ว +5

    I know a lot about C++, but still some stuff like auto is new. My BIG use so far of it, is to create a language. This language will later have so much features that it needs to have multiple languages to describe it, probably.

    • @vadiks20032
      @vadiks20032 2 ปีที่แล้ว

      as far as i understand programming is a big thing and you can't just learn C++ in 2000 and never ever learn anything new, because there are gonna be updates, there are gonna be new libraries, and other stuff. so it is not weird its new for you even though you know lots about C++

  • @hvvijuka
    @hvvijuka 2 ปีที่แล้ว

    you are really good in C++
    thanks

  • @arthur1112132
    @arthur1112132 4 ปีที่แล้ว +3

    I personally prefer to use 'auto' only in prototyping and research purpose. When I tests some stuff, 'auto' is kind of a quick way to do and try stuff. But once i finished to test and i'm actually working on a real project, i do preffer to use real types (or typedef/using for types that are really long or that mignt change in a future version). Also, typedef helps to change a whole ABI as well, but still restraining varibles to a single type. So changing types remains really easy that way :)

  • @koungmeng
    @koungmeng 5 ปีที่แล้ว +7

    std::unordered_map is just like a dictionary in python. That means it contain key , values pair:
    eg:
    std::unordered_map dict={
    {"one",1}, {"two",2}};
    std::cout

  • @Hazit90
    @Hazit90 5 ปีที่แล้ว

    thanks for the video. You answered a few questions :)

  • @michaelwplde
    @michaelwplde 4 ปีที่แล้ว +2

    1:40 auto for lambda variables is tremendously helpful... But if you need a specific base template type, might not be a good use for auto.

  • @01001000010101000100
    @01001000010101000100 ปีที่แล้ว

    That seems quite useful for prototyping. You know, a quick and dirty, short piece of code as POC, test if an idea works, then replace "auto" with proper types.

  • @fahimkamalahmed3544
    @fahimkamalahmed3544 5 ปีที่แล้ว

    The video was helpful. Thanks.

  • @leixun
    @leixun 4 ปีที่แล้ว +10

    *My takeaways:*
    1. *auto* could automatically work out what's data type suppose to be 0:11
    2. When we might not want to use *auto* 5:04
    3. A better way to use *auto* 8:58

    • @reynep
      @reynep 4 หลายเดือนก่อน

      Should be pinned

  • @lavi1172
    @lavi1172 3 ปีที่แล้ว

    very good video. thank you!

  • @zantazanta2906
    @zantazanta2906 3 ปีที่แล้ว

    Thanks for your good job

  • @michaelwplde
    @michaelwplde 4 ปีที่แล้ว +2

    11:00 Careful there, not sure whether constness, references i.e. & amp, are not conveyed in raw auto usage. 13:30 Exactly...

  • @anonymous-vj7jk
    @anonymous-vj7jk 2 ปีที่แล้ว

    thank you very much

  • @mrboyban
    @mrboyban 3 ปีที่แล้ว

    Great video, it is basically like an automagic.

  • @arod3295
    @arod3295 2 ปีที่แล้ว

    bless yo intelligent, puzzle solving soul

  • @Favo52
    @Favo52 3 ปีที่แล้ว +2

    So when looking in a map this would be a good use too?
    auto it = map.find(x);
    if (it != map.end())
    // do something

  • @erwinschrodinger2320
    @erwinschrodinger2320 3 ปีที่แล้ว +2

    Great!

  • @Kapil_Thakar
    @Kapil_Thakar 2 ปีที่แล้ว

    I am gonna watch all videos!!!!

  • @GenjaOrigins
    @GenjaOrigins 2 ปีที่แล้ว +1

    I wish you teach hashMap HashSet etc i see some so difficult examples and some simple ones

  • @blackwizards1692
    @blackwizards1692 5 ปีที่แล้ว

    Thanks for this! Couldn't understand the concept no matter how much I tried, now I did! Cheers

  • @annsgal2025
    @annsgal2025 ปีที่แล้ว +1

    The main reason I don't use auto is because it makes it impossible to detect integer overflows. I only use it for iterators.

  • @MsJavaWolf
    @MsJavaWolf 5 ปีที่แล้ว +4

    I also really like knowing my types and being explicit. Many people think C++ is too verbose, but I think it helps in bigger projects. In languages like Python you will often see a ton of comments instead, telling you what types a function is expecting etc. I quickly becomes as long or longer than C++ code, which is self documenting to a certain degree.

    • @simonmaracine4721
      @simonmaracine4721 5 ปีที่แล้ว

      Or just use type hints instead of comments.

  • @enjoylife6543
    @enjoylife6543 3 ปีที่แล้ว

    Great tut!
    8:06

  • @Mecolo
    @Mecolo 5 ปีที่แล้ว

    nice video!

  • @aritzh
    @aritzh 6 ปีที่แล้ว +2

    I know you would probably not use smart pointers, but what would you write:
    std::unique_ptr obj_ptr = std::make_unique(whatever);
    auto obj_ptr = std::make_unique(whatever);
    I am asking because std::unique_ptr is not that long, but for me it seems quite redundant, since the std::make_unique already tells the exact type

    • @rj00a
      @rj00a 6 ปีที่แล้ว +1

      I think most programmers would use auto there.

  • @CoolModderJaydonX
    @CoolModderJaydonX 8 หลายเดือนก่อน

    I usually just use auto for function pointers or something where I don't know what the type is.

  • @andregoulbourne839
    @andregoulbourne839 3 ปีที่แล้ว

    Very helpful, coding in java and needed a little translation.

  • @urduislamicstatus2107
    @urduislamicstatus2107 3 ปีที่แล้ว

    your english is amazing

    • @xzy7196
      @xzy7196 3 ปีที่แล้ว

      Why wouldn't it be? Like he is English.

  • @eddyecko94
    @eddyecko94 4 ปีที่แล้ว

    Normally use it with templates if the there's a possibility of different return types.

  • @chainonsmanquants1630
    @chainonsmanquants1630 3 ปีที่แล้ว

    Thanks

  • @billybollockhead5628
    @billybollockhead5628 2 ปีที่แล้ว

    On my team, we have a rule. If you use Auto, you need to have a VERY VERY VERY good reason to do so. As, personally, I like "self documenting" code, where I can debug something sometimes just by following it through. Usually, I can spot a bug just because auto has been used (coder thinks its a float, but it's an int, or something)

  • @ismail_
    @ismail_ 5 ปีที่แล้ว

    THANKS

  • @vhxhao
    @vhxhao 3 ปีที่แล้ว +4

    Will there be a performance difference between actual type and auto keyword?

    • @nonnullptrhuman504
      @nonnullptrhuman504 2 ปีที่แล้ว +2

      I don't think so.. Because the type is always known at compile time.

  • @marcinlesniewski4571
    @marcinlesniewski4571 3 ปีที่แล้ว

    Elegancko

  • @amarbs3287
    @amarbs3287 3 ปีที่แล้ว

    Is this done during preprocessing stage or compilation stage

  • @Krokoklemmee
    @Krokoklemmee 6 ปีที่แล้ว +1

    will you also cover decltype(auto) at some point in the future?

    • @platin2148
      @platin2148 6 ปีที่แล้ว

      OtakuNewb As it is part of the language surely.

  • @mattgraves3709
    @mattgraves3709 3 ปีที่แล้ว

    Result!

  • @mmaranta785
    @mmaranta785 3 ปีที่แล้ว

    You’re the best

  • @ChopsTwo
    @ChopsTwo 6 ปีที่แล้ว +6

    I think a better rule of thumb would be that you should specify the type explicitly when you need to know the type explicitly, and use auto when you don't, which is almost all the time really. It's still a strongly typed language, so the compiler will still make sure everything is correct.
    The idiom of using auto is common enough in the C++ community that it has a name, AAA, or Almost Always Auto.
    A real benefit to using auto even when the type is short is that implicit conversions are not allowed - so if the API changes and you have auto, there won't be unnecessary conversions all of a sudden, where there might be if you specified the type manually.
    Not a whole lot can be done to address the problem of needing to manually look up the type when you use auto, except that in my experience, it's much rarer to need to do that than it would seem at first glance.
    My recommendation would be to give both my and Cherno's strategies a go and see which you like - it really isn't *that* important which you choose. It will probably come down to what kind of work you do. I've done a lot of refactoring, and when a code base doesn't use auto, it tends to become a mindless task of changing the type to match the new type when auto would have just worked correctly, as well as unintended performance and correctness bugs from surprising type conversions that auto would have avoided.

  • @berktopbas1496
    @berktopbas1496 2 ปีที่แล้ว

    I cannot get the deduced "auto" type(int,char etc.) by compiler with mouseover in VS code(3:00) Is it an extension feature?

  • @544mamama
    @544mamama 3 ปีที่แล้ว +3

    1:24 am not gonna take 10 mins
    *takes 17 mins

  • @violinsheetmusicblog
    @violinsheetmusicblog 4 ปีที่แล้ว

    Can you make a video on iterators?

  • @alexissuarezalvarez5622
    @alexissuarezalvarez5622 4 ปีที่แล้ว +1

    can auto replace template?
    hi, can auto replace template? i am new to c ++ :(

  • @GenjaOrigins
    @GenjaOrigins 2 ปีที่แล้ว

    ordered unordered map videos please sir Di Cherno!!!

  • @killyourdarling9699
    @killyourdarling9699 7 หลายเดือนก่อน

    your accent is awesome

  • @prashantdhonde7891
    @prashantdhonde7891 4 ปีที่แล้ว

    Does auto helps in better memory management?

  • @kanithibharath
    @kanithibharath 4 ปีที่แล้ว

    HI Cherno. Very informative C++ features. Thanks. Can you make a video on Design patterns in C++?

  • @clemenswolfbartl5138
    @clemenswolfbartl5138 4 ปีที่แล้ว

    As a Kotlin developer, I have to say this is not an issue to not specify the type and just infer it, from the perspective that you can't read the type when you take a look at the declaration. The IntelliJ Idea has a feature that lets display the inferred type (in Kotlin). There is maybe a plugin to let display the inferred type in visual studio. This is more an tool problem than a language feature problem.

    • @andrefaustino5514
      @andrefaustino5514 ปีที่แล้ว

      I don't know before but, in MVS2022, if you double click ctrl it shows you the infer type before the var name, just like IntelliJ. I think C++ devs have a tendency of been extra careful with types, for understandable reasons, but auto can be helpful for a cleaner code.

  • @fishyperil2153
    @fishyperil2153 6 ปีที่แล้ว

    I was hoping you'd talk more about the "dark side" of auto ^^ you know, the stuff you mentioned in the end , how it can work with templates etc.
    But the video was still pretty useful . Up to now whenever I came across code that used auto I was never really sure what the reason for using it was. This helped clarify that a lot of it is just for convenience purposes.

  • @laike9m101
    @laike9m101 6 ปีที่แล้ว +1

    Can you make a video about move semantics?

  • @yunhuaji3038
    @yunhuaji3038 2 ปีที่แล้ว

    What's the plug-in/extension that you use to show the actual type of auto when hovering the cursor on the variable? Is it available for VScode on macOS? Thanks!

    • @Xiefux
      @Xiefux 2 ปีที่แล้ว

      it works for on vscode on linux

  • @fipabrate
    @fipabrate 6 ปีที่แล้ว +24

    i use auto to declare a lambda functions

  • @michelegobbato6290
    @michelegobbato6290 3 ปีที่แล้ว

    The Playlist for the C++ series is disappeard :-(

  • @StevenMartinGuitar
    @StevenMartinGuitar ปีที่แล้ว

    You have to decide whats the biggest time saver....not typing the huge data type three times in your code.... or not having to play Sherlock whenever you maintain the code or explain it to others

  • @Gojam12
    @Gojam12 2 ปีที่แล้ว

    My compiler disagree's with the char* returning a "Cherno". Any ideas why. I assume its because I am on a different C++. I believe I am on C++13 but not sure. In fact it causes two errors one on name.size() and the other on the char*.

  • @grzegorzdomagala9929
    @grzegorzdomagala9929 2 ปีที่แล้ว

    auto is a blessing - espacially when you need to declare iterator for std::list of std::map - and thank the holly c++ standard committee for "for(auto a : list) :)

  • @ShNeoteric
    @ShNeoteric 3 ปีที่แล้ว +1

    So auto is like the var variable in c#?

  • @pramodkumarkar8153
    @pramodkumarkar8153 4 ปีที่แล้ว

    excellent :)

  • @meer_kat5158
    @meer_kat5158 3 ปีที่แล้ว

    Hi
    char *GetName()
    {
    return "Hello";
    }
    this is a bot confusing. Won't this be destroyed when the scope ends? Can you return a pointer to an array on stack? Can you please explain how can a function return reference? It is very confusing.

  • @ankitjayswal5183
    @ankitjayswal5183 3 ปีที่แล้ว

    So when do we use & with auto?

  • @codysing8291
    @codysing8291 6 ปีที่แล้ว

    never seen a for loop like the one you did
    i normally use
    for(int i = 0; i < strings.size(); i++)
    {
    // do things
    }

    • @kocho4242
      @kocho4242 6 ปีที่แล้ว +2

      I normally use something shorter. Since C++11, it is recommended way to iterate through the container.
      for (auto& s : strings)
      {
      // do things
      }

  • @spwim
    @spwim 4 ปีที่แล้ว

    could auto be interesting when doing math-functions on mathematical operations?
    Like you could pass either doubles, floats, or ints to them?
    auto SomeFunction ( auto aNumber, auto anotherNumber){
    auto result = do some fance math;
    return result;
    }

    • @gtrsteve
      @gtrsteve หลายเดือนก่อน

      That is a sutuation for templates... :)

  • @DynamaticGamee0000
    @DynamaticGamee0000 2 ปีที่แล้ว +1

    What is ur laptop specs

  • @alltheway99
    @alltheway99 4 ปีที่แล้ว

    Is that a Pixel 2 XL next to you on the couch ?
    🙂

  • @manzoorahmed6048
    @manzoorahmed6048 5 ปีที่แล้ว

    Which software should I used for C++ programming? ??
    Which software you are using

    • @user-gj7nd7rb4v
      @user-gj7nd7rb4v 5 ปีที่แล้ว

      You mean IDE . it's visual studio

    • @Vitonolable
      @Vitonolable 4 ปีที่แล้ว

      also you can use Xcode, if you are on Mac

  • @imperfect_banda
    @imperfect_banda 3 ปีที่แล้ว

    Another great video brother. But you missed the fact that we can't use auto without initializing it(I think).
    Thanks for the great series.

    • @imperfect_banda
      @imperfect_banda 2 ปีที่แล้ว

      @Borislav Kamenov it's interesting. But how?

    • @imperfect_banda
      @imperfect_banda 2 ปีที่แล้ว

      @Borislav Kamenov Yeah brother, C++ does not allows to use it without initialisation.

  • @ImNotGam
    @ImNotGam 11 หลายเดือนก่อน

    I think the only time I've ever used auto is when I used auto specifically just so that I could use auto because I never had before. I very quickly changed it away from auto because it didn't help anything at all.

  • @Theawesomeking4444
    @Theawesomeking4444 2 ปีที่แล้ว +2

    so its basically How to turn C++ into Python

  • @spwim
    @spwim 4 ปีที่แล้ว +1

    could auto be interesting when doing math-functions on mathematical operations?
    auto SomeFunction ( auto aNumber, auto anotherNumber){
    auto result = do some fance math;
    return result;
    }

    • @Keregosh
      @Keregosh 4 ปีที่แล้ว

      Pretty sure you would use templates for that instead

    • @AyushSingh-lo4qo
      @AyushSingh-lo4qo 4 ปีที่แล้ว

      I think there would be a problem with this even if it does work in precision or simply deducing the type. Because of the different number of trailing points, Or even in big numbers where if a double and a double are multiplied and return type is an int we lose precision.

  • @soniablanche5672
    @soniablanche5672 5 หลายเดือนก่อน

    typescript and rust developers would use it all the time lol

  • @brahimchaouchi
    @brahimchaouchi 6 ปีที่แล้ว

    Very informative !
    Letting compiler guess type is named inference.

  •  4 ปีที่แล้ว

    The only place I use auto is in ranged for loops, simply because it is idiomatic.

  • @BobChess
    @BobChess 3 หลายเดือนก่อน

    Auto in C: 😭
    Auto in C++: 🗿

  • @Chiramisudo
    @Chiramisudo 4 ปีที่แล้ว +4

    Did you say Welcome to 2020? 😋

  • @Vermilicious
    @Vermilicious 4 ปีที่แล้ว +1

    Anything that is implicit is sort of bad, because it assumes some additional knowledge, and you have to think about multiple things at the same time when looking at it. Auto is such a thing, and the pointer-to-char constructor of the string class is another, which is mentioned in this video. I would just avoid these things if possible. I think perhaps they introduced auto to make the language seem more appealing compared to loosely typed languages, but if they really wanted to allow loose typing in C++, they should've tried to get rid of the auto keyword entirely (which would break a lot of things). I suspect auto will end up on lists of regret eventually.

  • @beaverundercover3479
    @beaverundercover3479 2 ปีที่แล้ว

    Thanks. For the time being as a beginner auto adds a layer of opacity and is therefore best avoided.

  • @bies_moron4404
    @bies_moron4404 6 ปีที่แล้ว

    yeah, new video !!!

  • @phantomstriker7996
    @phantomstriker7996 ปีที่แล้ว

    Auto automatically figures out what the variable type is supposed to be.