⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 this指针的用法(一般用于返回当前类事例)2.txt

📁 图像处理学习的一些心得
💻 TXT
字号:
C++ Specific —>

The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.

When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function call

myDate.setMonth( 3 );
can be interpreted this way:

setMonth( &myDate, 3 );
The object's address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.

The expression (*this) is commonly used to return the current object from a member function.

Note   Modifying the this pointer is illegal in the latest version of C++.

END C++ Specific

Example

// Example of the this pointer
void Date::setMonth( int mn )
{
   month = mn;            // These three statements
   this->month = mn;      //     are equivalent
   (*this).month = mn;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -