Cursor this in C ++
Each object in C ++ has access to its own location through an important pointer called this pointer. The pointer this in C ++ is a hidden parameter to all member functions. So inside a member function, this pointer can refer to the calling object.
The friend functions do not have this pointer, because friend is not a member of a class. Only member functions in C ++ have this this pointer.
Consider the following example to understand the concept of this pointer in C ++:
#include using namespace std ; class Box { public : // phan dinh nghia Constructor Box ( double dai = 1.0 , double rong = 1.0 , double cao = 1.0 ) { cout << "Constructor duoc goi!" << endl ; chieudai = dai ; chieurong = rong ; chieucao = cao ; } double theTich () { return chieudai * chieurong * chieucao ; } int sosanh ( Box box ) { return this -> theTich () > box . theTich (); } private : double chieudai ; // chieu dai cua mot box double chieurong ; // chieu rong cua mot box double chieucao ; // chieu cao cua mot box }; int main ( void ) { Box Box1 ( 2.4 , 4.2 , 2.2 ); // khai bao box1 Box Box2 ( 4.5 , 2.0 , 3.2 ); // khai bao box2 if ( Box1 . sosanh ( Box2 )) { cout << "Box2 la nho hon Box1" << endl ; } else { cout << "Box2 la bang hoac lon hon Box1" << endl ; } return 0 ; }
Compiling and running the above C ++ program will produce the following results:
According to Tutorialspoint
Previous article: Inline function in C ++
Next lesson: Cursor to class in C ++
3.5 ★ | 4 Vote
You should read it
- How to use Head Pointer on a Mac
- How to fix the mouse pointer disappearing on Windows 10
- Cursor NULL in C / C ++
- How to change the mouse pointer on Windows 11 with many styles and colors
- Cursor to class in C ++
- Object-oriented programming in PHP
- How to change the mouse pointer size and style in Windows 11
- How to change the pointer sensitivity, touchpad on a Mac
May be interested
- How to change the mouse cursor in Windowshow to change the mouse cursor in windows - in this article, i will show you how to change the mouse cursor in the following two main ways.
- Replace the mouse cursor with funny picturesinstead of the default windows mouse cursor, you can create more funny and lovely mouse pointers that suit your taste and help create more interest in working with computers.
- How to change the cursor size on the Debian 10 desktopdebian allows you to change the cursor size via the settings utility. you can access the settings utility through the application launcher search.
- Macromedia Flash - Dynamic cursor objectread this exercise and see how to create a dynamic cursor with just a few basic steps and of course use action script in flash 8.
- Macromedia Flash - Move objectswith this exercise, you will learn how to move any object with the cursor in flash 8 using the action script.
- The basic steps of fixing cursor cursors flutter in Windowsthe status of the mouse pointer jumps, the mouse is disordered or the mouse moves automatically while typing the keyboard occurs quite popular, it causes inhibition for the user to keep the mouse to hold the cursor back. this may be because the touchpad on your laptop is too sensitive or maybe because you accidentally touched the touchpad when typing. please try to apply the following corrections below.
- Macromedia Flash - Push objects away from the cursorthis tutorial will show you how to make a flash file with the effect of pushing the object away from the cursor by using some action script fragments in flash 8. let's look at the following example file.
- Create snow effect when moving mouse on Windowsin many parts of the world, snow began to fall and turn everything into a white color from the roof, the street, the park, the playground, everything looked like a long white sheet of paper. you can create snowfall in your computer using the cursor snowflakes software, making it snow every time you move the mouse on the screen.
- How to Restart Windows 8to restart windows 8, move the cursor to the upper/lower right corner → click → click the button → click . you can also use an alternate method that uses only the keyboard in situations where you cannot use the mouse. move your cursor to th...
- Mouse cursor spins error in Windows 10+11 and how to fix it quicklyare you feeling annoyed because the mouse pointer keeps spinning in windows 10+11? it's okay, tipsmake has measures in place