Advanced C++: Compiler Generated Functions

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024
  • Update on 9/22/12.
    C++ compiler silently generates a number of code for you. This short video talks about the 4 functions that are generated by compiler. Class notes can be downloaded from my website: boqian.weebly.com
    If code is not recognizable, increase RUclips video quality.

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

  • @BoQianTheProgrammer
    @BoQianTheProgrammer  11 лет назад +40

    I am glad that you seem to indicate there is something good in my accent :) I grew up in China and came to US in my twenties, so that is my natural tongue. I tried hard but apparently not very successful to get rid of my accent.

    • @simonw3858
      @simonw3858 8 лет назад +26

      Never get rid of your accent its cool. You are like the Jackie Chan of programming :) Your English is also quite good for someone of your heritage.

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

      you are the Bruce Lee of C++

  • @UnixGuy32
    @UnixGuy32 10 лет назад +4

    Mr.Qian,
    These videos are excellent. I am a C programmer trying to learn C++. I just did not know details about C++ and these videos are very helpful.
    Thank YOU!
    Altaf

  • @weili5342
    @weili5342 6 лет назад +18

    when destructor running, it first call data member's destructor, and then base class's destructor.

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

      exactly! I think there is a typo in the slides becuase did meantion that the order is reversed in the destructor

  • @BoQianTheProgrammer
    @BoQianTheProgrammer  11 лет назад +2

    That is correct. dynamic_cast can do that. For details, watch "All castings considered".

  • @ruchisingh3125
    @ruchisingh3125 5 месяцев назад

    Very nice content.. Great source of learning. The way you teaches is very good. Please upload more videos of latest features in C++

  • @delMYNOR
    @delMYNOR 10 лет назад +3

    best lessons ever. really. I know English little bit, but I've understood all of this

  • @byte_dance
    @byte_dance 12 лет назад

    Nice comment about default constructor, I had the wrong impression that the default constructor is the one without argument, thanks for the clarification.

  • @BoQianTheProgrammer
    @BoQianTheProgrammer  11 лет назад +1

    Thanks for your support.

  • @raviverma-rv5hc
    @raviverma-rv5hc 8 лет назад +9

    Thank you so much for your tutorials, I really a fan of your way of teaching and explanation.
    thanks so much!!!

  • @Pericotedelospalotes
    @Pericotedelospalotes 11 лет назад

    Hello Mr Bo Qian,
    I want to thank you for your response,I am thankfull also for yours videos,I will tell my friends about them.
    With our regards from us(Daniel ,Mr Fortachin and Miss Shakira)

  • @vANvTO
    @vANvTO 9 лет назад +3

    good to see you using VIM :)

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

    The simplest solution is collar(string color="red"), give the default value to the parameter....

  • @sr5726
    @sr5726 9 лет назад +1

    Thank you for all your videos, they are concise and simple to understand ( Aside, I like the way you say Bye bye :) )

  • @omkaraification
    @omkaraification 7 лет назад +2

    Very helpful video... Minor comment... there is typo in the output of Dog class.....Output should be "Henry is destroyed". However o/p shows "distroied" :)

  • @Pericotedelospalotes
    @Pericotedelospalotes 12 лет назад

    Hello Mr Bo Qian,I want to thank for your fast answer to my question,
    Daniel

  • @bijoy23
    @bijoy23 7 лет назад +2

    The destructor call order is written wrong ( at 1:00 time ), that should be reverse.

  • @zcecp49
    @zcecp49 8 лет назад +1

    @Bo Qian, your videos are fantastic! One question about this one - you say that the compiler does not auto-generate the functions which aren't used (e.g. the copy constructor). In your example, around 10:10, the compiler suggests a candidate function of the dog's copy constructor - but why is that a candidate? You've not attempted to use that function, so it shouldn't have been generated, right? I must be missing something....

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

    Member consts are static, and require program-wide initialization.

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

    In begining of video, Dog class example, which has nothing, there is no need to generate default constructor. Why you think compiler will generate default constructor.

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

    Hi Qian, thank you so much for the helpful video.
    One question regarding the first example:
    Why can't a reference member variable be copied in a compiler-generated copy assignment operator?
    Reference variables can be reassigned, right? Also looks like if I have a custom copy assignment operator, I am able to copy the reference from rhs object to this object.

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

      It's not the reassignment, but the initial assignment is never done, when the object is created.
      A reference always need to be assigned to an lvalue when created.
      In the example shown here, it's not assigned to any lvalue.

  • @haizhoushi4916
    @haizhoushi4916 8 лет назад +1

    really good course!

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

    One question :- if the class has const or reference member,then as explained copy constructor would not be provided by compiler.
    But in case there are multiple members like:-
    class B;
    class A{
    int a;
    const int b;
    B &ref;
    static int x;
    };
    So in this case apart from const and reference variables, there are other variables too, so still compiler wont generate the copy constructor.
    And in case we want to write our own assignment operator, how should we write it, please share your opinion.
    Thanks in advance!!

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

    Hi Bo. Can I ask you a question? If the compiler doesn't generate a move constructor, then what will happen when I use a rvalue to construct an instance whose class has no move constructor defined? Does it still use the copy constructor?

  • @maddy44s
    @maddy44s 9 лет назад +1

    Also, when you change m_name in Dog class as string & , the constructor initializer list need to be written.
    Default constructor written will not work

  • @BLang-bp2qj
    @BLang-bp2qj 8 лет назад

    In your example, you said the compiler only generated copy constructor when main function is using it. But if the class is in a seperate file as in class library, and they compile seperately, how did the complile if they are used or not?

  • @Pericotedelospalotes
    @Pericotedelospalotes 11 лет назад

    Yes It is Arturo(Daniel Arturo) yesterday you responded to me and I have another question that I am stuck with ...".... A cast may be used to convert a base-class pointer to a derived-class pointer.."
    Is it a False statement ?
    as I explained I am trying to learn programming from a book and this book has multiple choice question,
    Thank you very much ,
    Daniel Arturo.

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

    I am going to watch this whole series and report back

  • @pankajmalvi6761
    @pankajmalvi6761 8 лет назад

    hi Quian ,
    i was wondering if c++ 11 has already covered drawback , so do we have seperate tutorial for c++ 11 ?

  • @97NJK
    @97NJK 6 лет назад

    Why isn't copy constructor created by compiler in the first example? I thought it will be generated when dog2 = dog1? thanks!

  • @nancygarg9389
    @nancygarg9389 10 лет назад +1

    awesome videoo...

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

    Thank you for the lecture :)

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

    I love you!

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

    At 10:00, why copy constructor of dog generated when it’s not used? U said at 7:25 that no default functions r not generated if not used?

  • @margaretvanderbilt2123
    @margaretvanderbilt2123 11 лет назад

    Much Thanks. I can't say that enough : ) Very smart and helpful. I like the (slight) accent.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 6 лет назад

    Grt explanation

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

    but isnt a constructor with parameters is called a parameterized constructor

  • @eitanas85
    @eitanas85 7 лет назад +1

    ?& can someone please explain me more thouroghly why the code is not compiling when he changes String to String
    thanks!

    • @mayue6195
      @mayue6195 7 лет назад +1

      reference and const member is not copy assignable the copy assginment operator will be deleted in this case

    • @mayue6195
      @mayue6195 7 лет назад +1

      but they are copy constructable in normal cases

    • @mayue6195
      @mayue6195 7 лет назад +1

      when copy constructed const member will be a different member for new obj , but references will still be the same reference;

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

    are you using vim text editor?

  • @Pericotedelospalotes
    @Pericotedelospalotes 11 лет назад +1

    I f I could ask you another question please?
    Daniel

  • @rokolczuk
    @rokolczuk 8 лет назад +1

    what about move constructor?

    • @ldxyz-s1e
      @ldxyz-s1e 7 лет назад

      This is C++98. Look for "Modern C++" for 11.

  • @SahkanISR
    @SahkanISR 10 лет назад

    what is "operator=(const dog& rhs)" what does this "operator" do ?

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

      It might be too late but that is an overloaded function for the assignment operator ('=').
      Ideally it assigns your (this) object to the object on the right hand side thats why its called rhs.

  • @ldxyz-s1e
    @ldxyz-s1e 7 лет назад

    0:29
    2:41
    4:07

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

    it also generates dog.eat()

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

      LOL why

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

      @@MustaWizard it's in the new standard. look it up.

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

      @@Galal0110 XDDDDDD

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

      @@MustaWizard :D

  • @ajitsakri9888
    @ajitsakri9888 10 месяцев назад

    8:16

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

    watch at 1.25x speed... Thank me later !!

  • @queball39
    @queball39 11 лет назад

    Are you faking that accent?