This Pointer In C++
HTML-код
- Опубликовано: 4 фев 2025
- JOIN ME
-----
RUclips 🎬 / @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
You are my best teacher in C++
thanks man, you are a legend !!
5:42 looking for something in-depth like this, Superb!
Thanks..
please explain 2nd use of this pointer.
2) To return reference to the calling object
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?
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. :)
hello sir , what type of coder you uses..?
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
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.
You gained a subscriber ! Great Work !! really good Explained
Thanks dude!!
Sir,what should be circumstances at that time we can use function overloading???
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.
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 ?
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.
What will if we do return(*this) what this will return ?
great explanation! thanks
Thanks You So Much..
Wow amazing video thank you
Thanks..
sir please upload further concepts also ............
Yes man working on that part.. :)
What is the meaning of writing
Base(int a) :x{a} {}
Base(int a) { x = a; }
Helped thanks !!
why do we need 'this' pointer
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 RUclips you will get them, just search with my channel name.
Hard to stay focused when you have 50 ads in your video
Sorry but can't help here.
Its RUclips which decides how many ads should come, i just say RUclips can give ads at so and so places.
@@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.
@@pdxbound81 loved the last part 😍🤣
@@CppNuts use adblocks, it will decrease the frequency of ads
Thanks man
You're welcome!
Repeat after me: "Method" not "Meh turd"