Initializer List In C++

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 45

  • @benjahnz
    @benjahnz 4 года назад +3

    A great tutrial, clear and concise. Thanks!

  • @krishnakumar-pv1hb
    @krishnakumar-pv1hb Месяц назад

    During member initialisation don't use (), the compiler will give a level 2 warning. It's better to use { }

  • @thilakraj4207
    @thilakraj4207 2 года назад

    sir could you explain the use of '(int)x' which you used in the program?....I am not aware of that.

    • @CppNuts
      @CppNuts  2 года назад +1

      It’s called typecast.

  • @yc2158
    @yc2158 6 лет назад +3

    Do we have any specific name for the " : " which is used for initializing data members?

    • @yc2158
      @yc2158 6 лет назад +1

      I have to tell this "U R THE BEST". U made it simple n easy.😍👍

    • @CppNuts
      @CppNuts  6 лет назад +1

      As you already be knowing, it is collon, and thats the syntax for writing initializer list.

    • @CppNuts
      @CppNuts  6 лет назад

      Thank you so much.. :)

  • @dokodiaries
    @dokodiaries 4 года назад +1

    @CppNuts I think you are using sublime text how to setup it for ubuntu

    • @CppNuts
      @CppNuts  4 года назад

      I cannot explain it here, try Google and I am sure you will get. It`s pretty common

  • @crazymemes4080
    @crazymemes4080 6 месяцев назад

    have you ever noticed this initializer list in LEETCODE question if you check linked list question.

  • @charmingcat494
    @charmingcat494 2 года назад

    Hi Rupesh, I am using this textbook and a piece of code has me confused and you are the only person I could think of to ask. It seems like an object is being initialized within a function inside a class. is this possible?
    here is the code snippet below:
    void addInterest(int rate, int divisor) //function within DollarAmount class
    {
    DollarAmount interest { //DollarAmount is class name (is interest an object of DollarAmount?)
    (amount * rate + divisor / 2) /divisor
    }; //is this an initialization of interest?
    add(interest);
    }
    the book i am using is deitel c++ how to program and this is the example class given in chapter 5.

  • @RAMANKUMAR-xl4pr
    @RAMANKUMAR-xl4pr 6 лет назад +2

    thanks for your knowledge sir, You made it very simple and easy. Thanks

    • @CppNuts
      @CppNuts  6 лет назад

      Thanks dude!!!

  • @maverick7615
    @maverick7615 6 лет назад +2

    omg awesome video! you have made everything become crystal clear thanks man!!

    • @CppNuts
      @CppNuts  6 лет назад +1

      You are most welcome dude.. :)

  • @priteeshneema1574
    @priteeshneema1574 5 лет назад

    Thank You so Much Sir!!
    I DO HAVE ONE DOUBT: @5:01 u said {x=a} is assignment and x{a} is Initialisation. But when we do {x=a} doesnt it also perform the same operation as initialisation?

    • @indlamaheshkumarreddy9376
      @indlamaheshkumarreddy9376 5 лет назад

      it is initialisation using assignment operator

    • @aniketahir101
      @aniketahir101 4 года назад +3

      no..when object is constructed, compilers fills x with 0/garbage....later on the assignment is done x = a.
      Initialization list reduces one step...It directly initializes member with value when object is constructed.

    • @abrarulhaqshaik
      @abrarulhaqshaik 3 года назад +1

      @@aniketahir101 good comment. everything is clear now, thanks :)

    • @aniketahir101
      @aniketahir101 3 года назад +1

      @@abrarulhaqshaik great to know

  • @joelcurtis562
    @joelcurtis562 4 года назад +1

    Why use a member initializer list at all? It seems like the way you initialized the member variable x to start with was very intuitive and natural. This way just seems unnecessarily complicated, so I am wondering what is the payoff of having to learn a whole new syntax when a more familiar one seems to work just fine?

    • @CppNuts
      @CppNuts  4 года назад +1

      Hi Joel, good that you asked, here is the link where i have explained what are the different places where you will use initializer list.
      ruclips.net/video/vmMKXLuDgYQ/видео.html

  • @mapradnardev
    @mapradnardev 3 года назад

    when i use curely braces Base(int a):x{a} it is throwing error.Using curely braces instead of paranthesis is compiler dependent or what?

    • @CppNuts
      @CppNuts  3 года назад

      Yes upgrade to new compiler.

  • @DFsdf3443d
    @DFsdf3443d 6 лет назад

    but what if your member variable is an aggregate, wont it use aggregate initialization then? (which does allows narrowing - as far as i understand)
    im very confused about this whole initializer_list and aggregate initialization thing im sorry if this is completely wrong

  • @bhupeshpattanaik7150
    @bhupeshpattanaik7150 4 года назад

    Where is that video that was mentioned to be in description, I found too many playlist links but no video link

  • @samchau8011
    @samchau8011 3 года назад

    There is no link in the description where initializer list has to be used! please post it!

    • @CppNuts
      @CppNuts  3 года назад

      Thanks
      Added in description.
      ruclips.net/video/vmMKXLuDgYQ/видео.html

  • @bensalemmohamedabderrahman5844
    @bensalemmohamedabderrahman5844 4 года назад

    how can i initialize an array of objects when its private using the initialize list?

  • @videofountain
    @videofountain 5 лет назад

    Is this the class constructor member initializer list? Perhaps the name of video should be changed. It was clear to hear you differentiate between initialization and assignment.

    • @CppNuts
      @CppNuts  5 лет назад

      Initializer list is used to initialize data members.

  • @ks-op8pe
    @ks-op8pe 2 года назад

    informative and concise. Thx!

  • @justinhendrix3969
    @justinhendrix3969 Год назад

    Awesome video

  • @konstantinrebrov675
    @konstantinrebrov675 6 лет назад +1

    Thank you dear sir!

  • @janardhanreddy1180
    @janardhanreddy1180 4 года назад +1

    Awesome bro

  • @sallaklamhayyen9876
    @sallaklamhayyen9876 2 года назад

    thank you