本文共 1121 字,大约阅读时间需要 3 分钟。
#includeusing namespace std;class Stu {public: Stu(string name, int age) { this->name = name; this->age = age; } void prin() { cout << name << age << endl; }};
#includeusing namespace std;class String {public: String(const String& another) { if (another._str == _str) { return *this; } delete[] _str; _str = new char[another._str.size()]; memcpy(_str, another._str.c_str(), another._str.size()); return *this; }};
例如:
Stu* const growUp() { this->age++; return this;}
通过以上内容可以看出,this
指针在C++编程中具有重要的功能,广泛应用于构造函数的参数传递、多重赋值以及确保代码的可靠性等方面。
转载地址:http://psko.baihongyu.com/