Advanced C++: Disallow Functions

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

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

  • @pradyothanadamala4332
    @pradyothanadamala4332 6 лет назад +11

    "Friends are worse than enemies". wisdom lessons as well :-)

  • @ldxyz-s1e
    @ldxyz-s1e 8 лет назад +13

    To to avoid misunderstanding in 5:50: destructor and freeing object's memory are two different and unrelated things. Destructor is used to free member resources, that were explicitly allocated by the object, not to free the object itself. So, if there are no such members, destructor is not needed.
    Also, destructor doesn't call parent classes destructors or members destructors. They are get called outside of context of object's destructor. So, it have nothing to do with freeing parent's resources or member objects.
    Also, calling 'delete' on pointer that was not created by 'new' is always bad idea, because 'delete' primary function is to free memory allocated from heap (it have nothing to do with stack allocated objects). Anyway, the video is great!

    • @thestarinthesky_
      @thestarinthesky_ Год назад +1

      about your second statement, "Also, destructor doesn't call parent classes destructors or members destructors" seems to be partially incorrect. In C++, when an object is destroyed, the destructor does indeed get involved with the cleanup of its member objects and base classes. Here's how it works:
      When an object is destroyed, its destructor is called.
      After the derived class destructor's body is executed, the destructors of its base classes are called, in the reverse order of their appearance in the inheritance list.
      Additionally, the destructors for its member objects are called after the destructor body is executed and before the base class destructors are called. The member objects are destroyed in reverse order of their declaration.

  • @ebrahimesmaeilian
    @ebrahimesmaeilian 2 месяца назад

    i don't know you guys are the same as me or not by fully grasping and understanding this video i know 2 things:
    1- this guy gives like tons of information and even a single word from him has deep meaning behind it.
    2- i know absolutely nothing , i mean nothing literally about c++ and have to re-learn it again.

  • @MaheswaranSathiamoorthy
    @MaheswaranSathiamoorthy 7 лет назад +21

    Great video. You probably meant 'heap' instead of 'stack' at around 8:32.

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

      I guess he meant 'f' itself which is a pointer to OpenFile is stored on stack, which is correct.

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

    Yes, that was a typo. Nice catch. But even if you give g() a return type, the code will still error out, because copy constructor has no definition.

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

    Thank you for these wonderful videos. Please keep making more :)

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

    Very well explained all concept. Every video is very conceptual.
    Thanks man for your wonderful work, it helped alot

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

    Youu are a legend! and your series are amazing! so much useful information! :D

  • @tmszrs
    @tmszrs 11 лет назад +10

    At 4:16 you declare a method without a return type. The compiler then says '... forbids declaration of 'g' with no type'. It seems like this has nothing to do with copy constructing.

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

      Yes, it's wrong. To test, adding a proper return type to that method will give compiler error "Undefined reference to OpenFile::OpenFile(OpenFile& rhs)"

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

      It's a linker error.

  • @ManpreetSingh-og4fy
    @ManpreetSingh-og4fy 6 лет назад

    @Bo Qian Why have not you used
    OpenFile(const OpenFile&) as semantics of copy constructor.
    Woud not compiler generate a copy constructor with above semantics.
    #include
    using namespace std;
    class Test
    {
    public :
    Test(string s){cout

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

    'delete this;' should be replaced with '~OpenFile();' (yes - the destructor can be invoked just like any other method)

    • @hardstuck170
      @hardstuck170 7 лет назад

      I tried it, the compiler doesn't let you init. the object to begin with, because there is no accessible destructor.

  • @asadanees781
    @asadanees781 5 лет назад +1

    Nice explanation.

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

    I disagree At 4:35, error message is not because g() is not defined but because it has no return type. If you provide return type compilation will be successful but will be failed during linking as no definition is found.

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

    MinGW g++

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

    Good playlist Bo . Cheers

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

    It actually was printed out, but the console is too small so the printout was scrolled over.

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

    Mr. BoQian, very nice video. May I know which compiler are you using?

  • @rupeshmandke
    @rupeshmandke 9 лет назад

    This is so very useful Bo. Thank you so much :)

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

    I thought, based on the error message, that the error on line 52 g(OpenFile& f) stems from the fact that g is defined without a return type. Is that not the case?

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

    pls make more such viedos sir..
    cheers to you..
    thanks
    nagesh

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

    Simply GREAT BLESS YOU

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

    I have a question. when you moved the destructor onto the heap to successfully use it, it did not print out the body of the constuctor, only the destructor. why is that? Also, all these videos are very well done. Thank you for taken your time in doing this

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

    when we are crating the object on the HEAP using NEW and destroying using DELETE, why is that the private dtor still be called ?
    what is the role of such a private Dtor, ?

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

    These are great videos. Thanks.

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

    great videos :)

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

    summary --> 9:31

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

    Which 'g' method?

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

    How would the 'g' method work without a return type?

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

    Thank you Sir, if passable could you please create videos for Linux IPC

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

    Friends are our enemies. LOL

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

    he is using netneans i suppose! or oracle dev studio

  • @nileshkkulkarni
    @nileshkkulkarni 4 месяца назад

    4:34 your explanation of error is wrong. The error there is that method g(openFile& f); has no return type.

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

    what nameis your IDE?

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

    very interesting series and answers many questions ,
    but this video could definitely be summarized in 2-3 minutes instead of 10...
    No offense, keep up the good work...

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

    TOOOOOOOOOOOoo much ADVANce