This Pointer In C++

Sdílet
Vložit
  • čas přidán 29. 08. 2024

Komentáře • 38

  • @trilecao9014
    @trilecao9014 Před 2 lety

    You are my best teacher in C++

  • @prashantchavan2673
    @prashantchavan2673 Před 2 lety

    5:42 looking for something in-depth like this, Superb!

  • @aadarshbishen7078
    @aadarshbishen7078 Před 3 lety +1

    please explain 2nd use of this pointer.
    2) To return reference to the calling object

  • @RaviRahulKumarShah
    @RaviRahulKumarShah Před 5 lety +4

    You gained a subscriber ! Great Work !! really good Explained

  • @mba2ceo
    @mba2ceo Před 2 lety

    thank U again !!! Perfect explanation

  • @kfh13
    @kfh13 Před 6 lety +2

    So from compiler point of view object is only pointer to variables. Methods are redifiend as generic functions with namespaces and extra variable? How does data access (public and private) is interpreter? How does it works if we inherited from other classes or double inherited?

    • @CppNuts
      @CppNuts  Před 6 lety +2

      1. How does data access (public and private) is interpreter? : It is compile time checking whether it is allowed or not? If allowed then compiled successfully otherwise fail but if compile successfully then it is just generic call to that function.
      2. How does it works if we inherited from other classes or double inherited? : it works similarly again the compile time handling will happen and what ever the type of object is that function would be called. Now there is only one difference when there is a virtual functions involved, and to handle that there is another syntax.
      Example:
      class Base {
      int a;
      virtual void f();
      virtuaI void g();
      };
      class Derived: public Base {
      void g();
      };
      // in main()
      Base *pc;
      pc->g(2); // this line will be replaced with next line
      (*(pc->vptr[1]) )(pc,2);
      Now g() is a function and its entry is there in virtual table at index 1 that's the reason it is 1 there. Now only point is what pc is holding, if it is holding Base then it's Base class virtual table and there it will find g() belongs to Base , but if pc is holding Derived then it is holding virtual table which belongs to Derived then it will be having g() as Derived::g(), then Derived g() will be called.
      I hope you will get it. :)

  • @yourunclebob872
    @yourunclebob872 Před 4 lety +1

    Wow amazing video thank you

  • @bradkaf8670
    @bradkaf8670 Před 4 lety +1

    Helped thanks !!

  • @abhikeshu
    @abhikeshu Před 2 lety

    Hi, thanks for nice explanation, how compiler will deduce call for constructor to pass address of itself when object is not created yet, in other case Base::get(&b1) address of b1 is passed but how it will pass address on constructor when object is not created yet.

  • @tylersehon120
    @tylersehon120 Před 3 lety

    great explanation! thanks

  • @mba2ceo
    @mba2ceo Před 2 lety +1

    so use this always ?

    • @CppNuts
      @CppNuts  Před 2 lety +1

      I mean if you have to use then there is no other go.

  • @evolve1431
    @evolve1431 Před 3 lety

    Sir,correct me if i am not wrong what is the use of writing void set() method in class in these code ,because you already initialized the value using parameterized constructor so I think it is no need to create set method in this code

  • @anandadas4218
    @anandadas4218 Před 4 lety

    Sir my question is when b1 object called to the constructor that time we are not passing value into that object, so, in that case default constructor has to call . but how it will be call for set function both the time for b1 and b2 object creation ?

  • @addon8328
    @addon8328 Před 3 lety

    If this is a constant pointer then how it is pointing to the different objects. I mean constant pointer should not change the values they are pointing.

  • @prakashkrsingh0
    @prakashkrsingh0 Před 6 lety +1

    Sir,what should be circumstances at that time we can use function overloading???

    • @CppNuts
      @CppNuts  Před 6 lety

      The simplest example is when you want to add two integer then also you will call ADD function and when you want to add two float point number then also you will call ADD function but depending on inputs you must have two different function to handle this but generally you will keep function name as ADD. So here comes the function overloading.

  • @rameswarareddynv6583
    @rameswarareddynv6583 Před 6 lety +1

    sir please upload further concepts also ............

    • @CppNuts
      @CppNuts  Před 6 lety

      Yes man working on that part.. :)

  • @OSAMAKHAN-ek6cn
    @OSAMAKHAN-ek6cn Před rokem

    hello sir , what type of coder you uses..?

  • @prabhavdogra6567
    @prabhavdogra6567 Před 3 lety

    Thanks man

  • @rasishverma4716
    @rasishverma4716 Před 2 lety

    What will if we do return(*this) what this will return ?

  • @paul87173
    @paul87173 Před 4 lety +2

    why do we need 'this' pointer

    • @CppNuts
      @CppNuts  Před 4 lety

      C++ uses it to point to the address of the object you are dealing with in every member function of class.
      I have other videos on this pointer please visit them, or just search in CZcams you will get them, just search with my channel name.

  • @shradhapowar8095
    @shradhapowar8095 Před 3 lety

    What is the meaning of writing
    Base(int a) :x{a} {}

    • @CppNuts
      @CppNuts  Před 3 lety +4

      Base(int a) { x = a; }

  • @pdxbound81
    @pdxbound81 Před 5 lety +1

    Hard to stay focused when you have 50 ads in your video

    • @CppNuts
      @CppNuts  Před 5 lety

      Sorry but can't help here.
      Its CZcams which decides how many ads should come, i just say CZcams can give ads at so and so places.

    • @pdxbound81
      @pdxbound81 Před 4 lety +2

      @@CppNuts I hope they are at at least paying you for it! haha Every 2 minutes there was a new add. I now know more about C++ and where to buy cheaper car insurance.

    • @CppNuts
      @CppNuts  Před 4 lety +1

      @@pdxbound81 loved the last part 😍🤣

    • @shreeharjoshi6143
      @shreeharjoshi6143 Před 4 lety +1

      @@CppNuts use adblocks, it will decrease the frequency of ads

  • @RadicDotkey
    @RadicDotkey Před 4 lety +3

    Repeat after me: "Method" not "Meh turd"