This Pointer In C++

  Рет қаралды 32,996

CppNuts

CppNuts

6 жыл бұрын

JOIN ME
-----
KZfaq 🎬 / @cppnuts
Patreon 🚀 / cppnuts
COMPLETE PLAYLIST
------------
C++ Tutorial For Beginners: • Introduction To C++
STL (Standard Template Library): • STL In C++
ThreadIng In C++: • Multithreading In C++
Data Structures: • Data Structure
Algorithms: • Binary Search
Design Patterns: • Factory Design Pattern...
Smart Pointers: • Smart Pointer In C++
C++14: • Digit Separator In C++
C++17: • std string_view in C++...
C++ All Type Casts: • static_cast In C++
INTERVIEW PLAYLIST
------------
C++ Interview Q&A: • Structural Padding & P...
C++ Interview Q&A For Experienced: • How delete[] Knows How...
Linked List Interview Questions: • Find Kth Node From Bac...
BST Interview Questions: • Search Element In Bina...
Array Interview Questions: • Reverse An Array
String Interview Questions: • Check String Is Palind...
Bit Manipulation Questions: • Find Set Bit In Intege...
Binary Tree Interview Question: • Invert Binary Tree
Sorting Algorithms: • Bubble Sort
C++ MCQ: • Video
C MCQ: • What printf returns af...
C Interview Questions: • Designated Initializat...
QUICK SHORT VIDEOS
-------------
C++ Short : • C++ Short Videos
C Short : • Shorts C Programming MCQ
In this video we will learn what is "this pointer" in c++ programming language.
There few points about the same as:
0. this pointer is used to hold the address of current object (using which we have called particular member function).
1. this pointer is a const pointer.
2. this pointer is passed as a hidden argument to non-static member functions.
3. Compiler automatically changes all data member access with this pointer.
4. It is not passed in static member functions.
#cpp #programming #tutorial #coding

Пікірлер: 38
@evolve1431
@evolve1431 3 жыл бұрын
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
@bradkaf8670
@bradkaf8670 4 жыл бұрын
Helped thanks !!
@anandadas4218
@anandadas4218 4 жыл бұрын
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 ?
@mba2ceo
@mba2ceo 2 жыл бұрын
thank U again !!! Perfect explanation
@trilecao9014
@trilecao9014 2 жыл бұрын
You are my best teacher in C++
@abhikeshu
@abhikeshu 2 жыл бұрын
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.
@OSAMAKHAN-ek6cn
@OSAMAKHAN-ek6cn Жыл бұрын
hello sir , what type of coder you uses..?
@aadarshbishen7078
@aadarshbishen7078 3 жыл бұрын
please explain 2nd use of this pointer. 2) To return reference to the calling object
@kfh13
@kfh13 6 жыл бұрын
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 6 жыл бұрын
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. :)
@RaviRahulKumarShah
@RaviRahulKumarShah 5 жыл бұрын
You gained a subscriber ! Great Work !! really good Explained
@CppNuts
@CppNuts 5 жыл бұрын
Thanks dude!!
@rasishverma4716
@rasishverma4716 2 жыл бұрын
What will if we do return(*this) what this will return ?
@addon8328
@addon8328 2 жыл бұрын
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.
@yourunclebob872
@yourunclebob872 4 жыл бұрын
Wow amazing video thank you
@CppNuts
@CppNuts 4 жыл бұрын
Thanks..
@tylersehon120
@tylersehon120 3 жыл бұрын
great explanation! thanks
@CppNuts
@CppNuts 3 жыл бұрын
Thanks You So Much..
@prakashkrsingh0
@prakashkrsingh0 6 жыл бұрын
Sir,what should be circumstances at that time we can use function overloading???
@CppNuts
@CppNuts 6 жыл бұрын
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.
@prashantchavan2673
@prashantchavan2673 2 жыл бұрын
5:42 looking for something in-depth like this, Superb!
@CppNuts
@CppNuts 2 жыл бұрын
Thanks..
@prabhavdogra6567
@prabhavdogra6567 3 жыл бұрын
Thanks man
@CppNuts
@CppNuts 3 жыл бұрын
You're welcome!
@mba2ceo
@mba2ceo 2 жыл бұрын
so use this always ?
@CppNuts
@CppNuts 2 жыл бұрын
I mean if you have to use then there is no other go.
@rameswarareddynv6583
@rameswarareddynv6583 6 жыл бұрын
sir please upload further concepts also ............
@CppNuts
@CppNuts 6 жыл бұрын
Yes man working on that part.. :)
@shradhapowar8095
@shradhapowar8095 3 жыл бұрын
What is the meaning of writing Base(int a) :x{a} {}
@CppNuts
@CppNuts 3 жыл бұрын
Base(int a) { x = a; }
@paul87173
@paul87173 4 жыл бұрын
why do we need 'this' pointer
@CppNuts
@CppNuts 4 жыл бұрын
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 KZfaq you will get them, just search with my channel name.
@pdxbound81
@pdxbound81 4 жыл бұрын
Hard to stay focused when you have 50 ads in your video
@CppNuts
@CppNuts 4 жыл бұрын
Sorry but can't help here. Its KZfaq which decides how many ads should come, i just say KZfaq can give ads at so and so places.
@pdxbound81
@pdxbound81 4 жыл бұрын
@@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 4 жыл бұрын
@@pdxbound81 loved the last part 😍🤣
@shreeharjoshi6143
@shreeharjoshi6143 4 жыл бұрын
@@CppNuts use adblocks, it will decrease the frequency of ads
@RadicDotkey
@RadicDotkey 4 жыл бұрын
Repeat after me: "Method" not "Meh turd"
Friend Function | Friend Class In C++
16:26
CppNuts
Рет қаралды 26 М.
Static Data Member And Static Member Function In C++
17:19
CppNuts
Рет қаралды 51 М.
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
Nutella bro sis family Challenge 😋
00:31
Mr. Clabik
Рет қаралды 12 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 126 МЛН
Bit Fields In C & C++
20:36
CppNuts
Рет қаралды 21 М.
Virtual Function In C++
15:08
CppNuts
Рет қаралды 34 М.
SMART POINTERS in C++ (for beginners in 20 minutes)
24:32
CodeBeauty
Рет қаралды 95 М.
A const int is not a constant.
9:16
Jacob Sorber
Рет қаралды 66 М.
C++ Pointers - Finally Understand Pointers
15:56
Caleb Curry
Рет қаралды 208 М.
Inline Function In C++
17:45
CppNuts
Рет қаралды 30 М.
Const Data Member In C++
15:03
CppNuts
Рет қаралды 22 М.
C++ Weekly - Ep 322 - Top 4 Places To Never Use `const`
18:53
C++ Weekly With Jason Turner
Рет қаралды 34 М.
POINTERS in C++
16:59
The Cherno
Рет қаралды 1 МЛН